package com.fh.controller.building.bill;


import com.fh.controller.base.BaseController;
import com.fh.controller.system.tools.PushToApp;
import com.fh.entity.Page;
import com.fh.entity.system.User;
import com.fh.service.attachment.AttachmentService;
import com.fh.service.building.RecordService;
import com.fh.service.building.bill.BillService;
import com.fh.service.building.contract.ContractService;
import com.fh.service.building.contract.LoanService;
import com.fh.service.business.BusinessService;
import com.fh.service.property.PropertyService;
import com.fh.service.role.ShsRoleService;
import com.fh.service.system.user.UserService;
import com.fh.util.*;
import net.sf.json.JSONArray;
import net.sf.json.JSONException;
import net.sf.json.JSONObject;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.session.Session;
import org.apache.shiro.subject.Subject;
import org.springframework.stereotype.Controller;
import org.springframework.transaction.PlatformTransactionManager;
import org.springframework.transaction.TransactionDefinition;
import org.springframework.transaction.TransactionStatus;
import org.springframework.transaction.support.DefaultTransactionDefinition;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.text.DecimalFormat;
import java.text.NumberFormat;
import java.util.*;

import static com.fh.controller.system.tools.GetDatalayui.getLData;
import static com.fh.controller.system.tools.GetDatalayui.getPData;

/**
 * Created by caozengling on 2017/10/2.
 */
@Controller
@RequestMapping(value = "/billController")
public class BillController extends BaseController {
    @Resource(name = "billService")
    private BillService billService;
    @Resource(name = "recordService")
    private RecordService recordService;
    @Resource(name = "attachmentService")
    private AttachmentService attachmentService;
    @Resource(name = "propertyService")
    private PropertyService propertyService;
    @Resource(name = "contractService")
    private ContractService contractService;
    @Resource(name = "shsRoleService")
    private ShsRoleService roleService;
    @Resource(name = "userService")
    private UserService userService;
    @Resource(name = "businessService")
    private BusinessService businessService;
    @Resource
    private PlatformTransactionManager transactionManager;
    @Resource(name = "loanService")
    private LoanService loanService;


    /**
     * 返回list 停车场卖卡
     */
    @RequestMapping(value = "/listSellCards")
    @ResponseBody
    public Object listSellCards(Page page) {
        PageData pd = new PageData();
        Map<String, Object> map = new HashMap<String, Object>();
        List<PageData> varList = new ArrayList<>();
        String datalayui = null;
        //获取当前登录用户
        Subject currentUser = SecurityUtils.getSubject();
        Session session = currentUser.getSession();
        User user = (User) session.getAttribute(Const.SESSION_USER);
        try {
            pd = this.getPageData();
            getPData(page, pd);
            pd.put("USER_ID", user.getUSER_ID());
            varList = billService.findlistPageSellCards(page);
            datalayui = getLData(page, varList);
        } catch (Exception e) {
            logger.error(e.toString(), e);
        } finally {
            logAfter(logger);
        }
        return datalayui;
    }


    /**
     * 返回list 停车场  临时性消费
     */
    @RequestMapping(value = "/listInterim")
    @ResponseBody
    public Object listInterim(Page page) {
        PageData pd = new PageData();
        Map<String, Object> map = new HashMap<String, Object>();
        List<PageData> varList = new ArrayList<>();
        String datalayui = null;
        //获取当前登录用户
        Subject currentUser = SecurityUtils.getSubject();
        Session session = currentUser.getSession();
        User user = (User) session.getAttribute(Const.SESSION_USER);
        try {
            pd = this.getPageData();
            pd.put("USER_ID", user.getUSER_ID());
            getPData(page, pd);
            varList = billService.findlistPageInterim(page);
            datalayui = getLData(page, varList);
        } catch (Exception e) {
            logger.error(e.toString(), e);
        } finally {
            logAfter(logger);
        }
        return datalayui;
    }


    /**
     * 新增买卡账单
     */
    @RequestMapping(value = "/saveCard")
    @ResponseBody
    public PageData saveCard() {
        logBefore(logger, "新增账单");
        PageData res = new PageData();
        PageData pd = this.getPageData();
        //获取当前登录用户
        Subject currentUser = SecurityUtils.getSubject();
        Session session = currentUser.getSession();
        User user = (User) session.getAttribute(Const.SESSION_USER);
        try {
            //JSONArray jsonArray=JSONArray.fromObject(pd);
            //获得jsonArray的第一个元素
            //Object o=jsonArray.get(0);
            JSONObject jsonObject2 = JSONObject.fromObject(pd);
            //JSONHelper.json2Map(jsonObject2.get("sendData[DATA]").toString());
            Map map1 = JSONHelper.json2Map(jsonObject2.get("sendData[DATA]").toString());
            List<PageData> billlist = propertyService.listAllPro(pd);//获取所有账单类型
            Set<Object> keySet = map1.keySet();
            //有了Set集合。就可以获取其迭代器。
            Iterator<Object> it = keySet.iterator();
            //租金id
            String BID = this.get32UUID();
            int part = 0;//统计杂费第几个paet
            int zujinyajin = 1;//统计杂费第几个paet
            Object key = it.next();
            //有了键可以通过map集合的get方法获取其对应的值。
            Object value = (Object) map1.get(key);
            //System.out.println(value.toString());
            List<PageData> list2 = (List<PageData>) JSONArray.toList(JSONArray.fromObject(value.toString()), PageData.class);
            for (PageData stu : list2) {
                PageData billroom = new PageData();//创建新账单 如果房间存在合同 就在合同中增加账单 如果不存在合同 添加无合同账单
                billroom.put("ROOM_ID", stu.get("ROOM_ID").toString());
                List<PageData> ishavecontract = billService.isHaveContract(billroom);
                if (ishavecontract.size() > 0) {
                    billroom.put("CONTRACT_ID", ishavecontract.get(0).get("CONTRACT_ID").toString());
                }
                //version 1 暂时写死

                if (jsonObject2.containsKey("data1[租金]")) {
                    String zuid = this.get32UUID();
                    billroom.put("ID", zuid);
                    billroom.put("CREATE_ID", user.getUSER_ID());
                    billroom.put("CREATE_DATE", DateUtil.getTime());
                    billroom.put("UPDATE_DATE", DateUtil.getTime());//
                    billroom.put("UPDATE_ID", user.getUSER_ID()); //
                    billroom.put("SORT", "0");
                    billroom.put("IS_DEL", "0");
                    billroom.put("BILL_SIGNER", jsonObject2.getString("data1[BILL_SIGNER]").toString());
                    billroom.put("START_DATE", jsonObject2.getString("data1[START_DATE]"));
                    billroom.put("END_DATE", jsonObject2.getString("data1[END_DATE]"));
                    billroom.put("PAY_DATE", jsonObject2.getString("data1[PAY_DATE]"));
                    billroom.put("ROOM_ID", stu.get("ROOM_ID").toString());
                    billroom.put("BILL_NAME", jsonObject2.getString("data1[zujin]"));
                    billroom.put("BILL_TYPE", 0);//增加租金类型
                    billroom.put("TOTAL_PRICE", jsonObject2.getString("data1[租金]"));
                    billroom.put("INFO", jsonObject2.getString("data1[INFO]"));
                    billroom.put("STATE", "682177ade393478e8224f9a3aa385a6c");
                    billroom.put("CHECK_STATE", "0");//手动添加账单 暂时归到 待审核中
                    billroom.put("MAKE_BILL_TYPE", "1");//手动添加
                    billroom.put("PRICE_TYPE", jsonObject2.getString("data1[PRICE_TYPE1]"));//支出  收入
                    billroom.put("ALLOT_BILL", jsonObject2.getString("data1[ALLOT_BILL1]"));//公户 私户
                    billService.save(billroom);
                    //租金附件
                    if (jsonObject2.containsKey("data1[ATTACHMENT][0][name]")) {
                        PageData pds = new PageData();
                        pds.put("ID", this.get32UUID());    //主键
                        pds.put("OID", zuid);
                        pds.put("NAME", pd.get("data1[ATTACHMENT][0][name]"));
                        pds.put("EXT", pd.get("data1[ATTACHMENT][0][ext]"));
                        pds.put("PATH", pd.get("data1[ATTACHMENT][0][url]"));
                        pds.put("TYPE", "bill");
                        pds.put("SORT", "1");
                        pds.put("REMARK", "");
                        pds.put("CREATE_TIME", new DateUtil().getTime());
                        pds.put("CREATE_ID", user.getUSER_ID());
                        pds.put("IS_DELETED", 0);
                        attachmentService.saveAttachment(pds);
                    }
                    //保存操作记录
                    PageData oppd = new PageData();
                    oppd.put("ID", this.get32UUID());    //主键
                    oppd.put("IS_DEL", 0); //是否删除
                    oppd.put("SORT", 0); //排序
                    oppd.put("BILL_ID", zuid); //排序
                    oppd.put("CREATE_ID", user.getUSER_ID()); //创建用户
                    oppd.put("CREATE_DATE", new DateUtil().getTime()); //创建时间
                    //oppd.put("DETAILS","新增一个"+pd.get("BILL_NAME").toString()+"账单,金额"+pd.get("TOTAL_PRICE").toString());
                    oppd.put("DETAILS", "新增一个账单");
                    oppd.put("OPERA_TIME", new DateUtil().getTime());
                    oppd.put("OPERATOR", user.getNAME());
                    recordService.save(oppd);

                }
                //同时添加 多个 租金的处理方法
                for (int i = 1; i < pd.size(); i++) {
                    if (jsonObject2.containsKey("data1[租金" + i + "]")) {
                        String zuid = this.get32UUID();
                        billroom.put("ID", zuid);
                        billroom.put("CREATE_ID", user.getUSER_ID());
                        billroom.put("CREATE_DATE", DateUtil.getTime());
                        billroom.put("SORT", "0");
                        billroom.put("IS_DEL", "0");
                        billroom.put("BILL_SIGNER", jsonObject2.getString("data1[BILL_SIGNER]").toString());
                        billroom.put("START_DATE", jsonObject2.getString("data1[START_DATE]"));
                        billroom.put("END_DATE", jsonObject2.getString("data1[END_DATE]"));
                        billroom.put("PAY_DATE", jsonObject2.getString("data1[PAY_DATE]"));
                        billroom.put("ROOM_ID", stu.get("ROOM_ID").toString());
                        billroom.put("BILL_TYPE", 0);//增加租金类型
                        billroom.put("BILL_NAME", jsonObject2.getString("data1[zujin]"));
                        billroom.put("TOTAL_PRICE", jsonObject2.getString("data1[租金" + i + "]"));
                        billroom.put("INFO", jsonObject2.getString("data1[INFO]"));
                        billroom.put("STATE", "682177ade393478e8224f9a3aa385a6c");
                        billroom.put("CHECK_STATE", "0");//手动添加账单 暂时归到 待审核中
                        billroom.put("MAKE_BILL_TYPE", "1");//手动添加
                        billroom.put("PRICE_TYPE", jsonObject2.getString("data1[PRICE_TYPE" + i + "]"));//支出  收入
                        billroom.put("ALLOT_BILL", jsonObject2.getString("data1[ALLOT_BILL" + i + "]"));//公户 私户
                        billService.save(billroom);
                        //保存操作记录
                        PageData oppd = new PageData();
                        oppd.put("ID", this.get32UUID());    //主键
                        oppd.put("IS_DEL", 0); //是否删除
                        oppd.put("SORT", 0); //排序
                        oppd.put("BILL_ID", zuid); //排序
                        oppd.put("CREATE_ID", user.getUSER_ID()); //创建用户
                        oppd.put("CREATE_DATE", new DateUtil().getTime()); //创建时间
                        //oppd.put("DETAILS","新增一个"+pd.get("BILL_NAME").toString()+"账单,金额"+pd.get("TOTAL_PRICE").toString());
                        oppd.put("DETAILS", "新增一个账单");
                        oppd.put("OPERA_TIME", new DateUtil().getTime());
                        oppd.put("OPERATOR", user.getNAME());
                        recordService.save(oppd);
                    }
                }


                if (jsonObject2.containsKey("data1[押金]")) {
                    String yaid = this.get32UUID();
                    billroom.put("ID", yaid);
                    billroom.put("CREATE_ID", user.getUSER_ID());
                    billroom.put("CREATE_DATE", DateUtil.getTime());
                    billroom.put("SORT", "0");
                    billroom.put("IS_DEL", "0");
                    billroom.put("BILL_SIGNER", jsonObject2.getString("data1[BILL_SIGNER]").toString());
                    billroom.put("START_DATE", jsonObject2.getString("data1[START_DATE]"));
                    billroom.put("END_DATE", jsonObject2.getString("data1[END_DATE]"));
                    billroom.put("PAY_DATE", jsonObject2.getString("data1[PAY_DATE]"));
                    billroom.put("ROOM_ID", stu.get("ROOM_ID").toString());
                    billroom.put("BILL_TYPE", 1);//增加押金类型
                    billroom.put("BILL_NAME", jsonObject2.getString("data1[yajin]"));
                    billroom.put("TOTAL_PRICE", jsonObject2.getString("data1[押金]"));
                    billroom.put("INFO", jsonObject2.getString("data1[INFO]"));
                    billroom.put("STATE", "682177ade393478e8224f9a3aa385a6c");
                    billroom.put("CHECK_STATE", "0");//手动添加账单 暂时归到 待审核中
                    billroom.put("ALLOT_BILL", "0");//公户 私户
                    billroom.put("MAKE_BILL_TYPE", "1");//手动添加
                    billroom.put("PRICE_TYPE", jsonObject2.getString("data1[PRICE_TYPE1]"));//支出  收入
                    billService.save(billroom);
                    //押金附件
                    if (jsonObject2.containsKey("data1[ATTACHMENT][0][name]")) {
                        PageData pds = new PageData();
                        pds.put("ID", this.get32UUID());    //主键
                        pds.put("OID", yaid);
                        pds.put("NAME", pd.get("data1[ATTACHMENT][0][name]"));
                        pds.put("EXT", pd.get("data1[ATTACHMENT][0][ext]"));
                        pds.put("PATH", pd.get("data1[ATTACHMENT][0][url]"));
                        pds.put("TYPE", "bill");
                        pds.put("SORT", "1");
                        pds.put("REMARK", "");
                        pds.put("CREATE_TIME", new DateUtil().getTime());
                        pds.put("CREATE_ID", user.getUSER_ID());
                        pds.put("IS_DELETED", 0);
                        attachmentService.saveAttachment(pds);
                    }
                    //保存操作记录
                    PageData oppd = new PageData();
                    oppd.put("ID", this.get32UUID());    //主键
                    oppd.put("IS_DEL", 0); //是否删除
                    oppd.put("SORT", 0); //排序
                    oppd.put("BILL_ID", yaid); //排序
                    oppd.put("CREATE_ID", user.getUSER_ID()); //创建用户
                    oppd.put("CREATE_DATE", new DateUtil().getTime()); //创建时间
                    //oppd.put("DETAILS","新增一个"+pd.get("BILL_NAME").toString()+"账单,金额"+pd.get("TOTAL_PRICE").toString());
                    oppd.put("DETAILS", "新增一个账单");
                    oppd.put("OPERA_TIME", new DateUtil().getTime());
                    oppd.put("OPERATOR", user.getNAME());
                    recordService.save(oppd);
                }

                //同时添加 多个 押金的处理方法
                for (int i = 1; i < pd.size(); i++) {
                    if (jsonObject2.containsKey("data1[押金" + i + "]")) {
                        zujinyajin++;
                        String yaid = this.get32UUID();
                        billroom.put("ID", yaid);
                        billroom.put("CREATE_ID", user.getUSER_ID());
                        billroom.put("CREATE_DATE", DateUtil.getTime());
                        billroom.put("SORT", "0");
                        billroom.put("IS_DEL", "0");
                        billroom.put("BILL_SIGNER", jsonObject2.getString("data1[BILL_SIGNER]").toString());
                        billroom.put("START_DATE", jsonObject2.getString("data1[START_DATE]"));
                        billroom.put("END_DATE", jsonObject2.getString("data1[END_DATE]"));
                        billroom.put("PAY_DATE", jsonObject2.getString("data1[PAY_DATE]"));
                        billroom.put("ROOM_ID", stu.get("ROOM_ID").toString());
                        billroom.put("BILL_TYPE", 1);//增加押金类型
                        billroom.put("BILL_NAME", jsonObject2.getString("data1[yajin]"));
                        billroom.put("TOTAL_PRICE", jsonObject2.getString("data1[押金" + zujinyajin + "]"));
                        billroom.put("INFO", jsonObject2.getString("data1[INFO]"));
                        billroom.put("STATE", "682177ade393478e8224f9a3aa385a6c");
                        billroom.put("CHECK_STATE", "0");//手动添加账单 暂时归到 待审核中
                        billroom.put("MAKE_BILL_TYPE", "1");//手动添加
                        billroom.put("PRICE_TYPE", jsonObject2.getString("data1[PRICE_TYPE" + zujinyajin + "]"));//支出  收入
                        billroom.put("ALLOT_BILL", jsonObject2.getString("data1[ALLOT_BILL" + zujinyajin + "]"));//公户 私户
                        billService.save(billroom);
                        //保存操作记录
                        PageData oppd = new PageData();
                        oppd.put("ID", this.get32UUID());    //主键
                        oppd.put("IS_DEL", 0); //是否删除
                        oppd.put("SORT", 0); //排序
                        oppd.put("BILL_ID", yaid); //排序
                        oppd.put("CREATE_ID", user.getUSER_ID()); //创建用户
                        oppd.put("CREATE_DATE", new DateUtil().getTime()); //创建时间
                        //oppd.put("DETAILS","新增一个"+pd.get("BILL_NAME").toString()+"账单,金额"+pd.get("TOTAL_PRICE").toString());
                        oppd.put("DETAILS", "新增一个账单");
                        oppd.put("OPERA_TIME", new DateUtil().getTime());
                        oppd.put("OPERATOR", user.getNAME());
                        recordService.save(oppd);
                    }
                }
                //获取 所有存在的账单

                // billlists.get("CODE");
                //if(jsonObject2.get("data1").equals(billlists.get("CODE"))){
                StringBuilder sb = new StringBuilder();
                String sbString = "";
                try {
                    Iterator iterator = jsonObject2.keys();
                    while (iterator.hasNext()) {
                        String key2 = (String) iterator.next();
                        //CollectionUtils.isEmpty((Collection) jsonObject2.get(key2));
                        //获取已经填写的 账单类型
                        if (StringHelper.isNotEmpty(jsonObject2.get(key2).toString())) {
                            //System.out.println(jsonObject2.get(key2));
                            //System.out.println(key2);
                            //获取 账单类型 金额 数据

                            for (PageData billlists : billlist) {
                                if ((key2.toString()).contains(billlists.get("CODE").toString())) {
                                    //System.out.println(billlists.get("CODE"));
                                    part++;
                                    String zaid = this.get32UUID();
                                    billroom.put("ID", zaid);
                                    billroom.put("CREATE_ID", user.getUSER_ID());
                                    billroom.put("CREATE_DATE", DateUtil.getTime());
                                    billroom.put("SORT", "0");
                                    billroom.put("IS_DEL", "0");
                                    billroom.put("BILL_SIGNER", jsonObject2.getString("data1[BILL_SIGNER]").toString());
                                    billroom.put("START_DATE", jsonObject2.getString("data1[START_DATE]"));
                                    billroom.put("END_DATE", jsonObject2.getString("data1[END_DATE]"));
                                    billroom.put("PAY_DATE", jsonObject2.getString("data1[PAY_DATE]"));
                                    billroom.put("ROOM_ID", stu.get("ROOM_ID").toString());
                                    billroom.put("BILL_TYPE", 2);//增加其他类型账单
                                    billroom.put("BILL_NAME", billlists.get("CODE"));
                                    billroom.put("TOTAL_PRICE", jsonObject2.getString("" + key2 + ""));
                                    billroom.put("INFO", jsonObject2.getString("data1[INFO]"));
                                    if ("停车费".equals(billlists.get("CODE").toString())) {
                                        if ("2".equals(jsonObject2.getString("data1[MKXF]"))) {//买卡
                                            billroom.put("STATE", "eda58d7280554dd9918207d27e2d4654");//已收款
                                            billroom.put("CHECK_STATE", "1");//手动添加账单 暂时归到 待审核中
                                            billroom.put("PARK_CARD", jsonObject2.getString("data1[PARK_CARD" + part + "]"));
                                            billroom.put("PRICE_TYPE", "0");//不是收入支出了  是 买卡 和消费
                                            billroom.put("ROOM_ID", jsonObject2.getString("data1[ROOMID" + part + "]"));//停车场多选房间
                                            billroom.put("ALLOT_BILL", jsonObject2.getString("data1[ALLOT_BILL" + part + "]"));
                                        } else {
                                            if ("1".equals(jsonObject2.getString("data1[PRICE_TYPE1]"))) {// 1卡  收入2
                                                billroom.put("TOTAL_PRICE", "");//消费的时候 不存price
                                                billroom.put("STATE", "eda58d7280554dd9918207d27e2d4654");//已收款
                                                billroom.put("PRICE_TYPE", "0");//不是收入支出了  是 买卡 和消费
                                                billroom.put("PARK_CARD", jsonObject2.getString("data1[PARK_CARD" + part + "]"));
                                                billroom.put("ALLOT_BILL", jsonObject2.getString("data1[ALLOT_BILL" + part + "]"));
                                                if (jsonObject2.containsKey("data1[PART_START" + part + "]")) {
                                                    billroom.put("PART_START", jsonObject2.getString("data1[PART_START" + part + "]"));
                                                }
                                                if (jsonObject2.containsKey("data1[PART_END" + part + "]")) {
                                                    billroom.put("PART_END", jsonObject2.getString("data1[PART_END" + part + "]"));
                                                }
                                            } else {//收入的时候 存现金账户
                                                billroom.put("TOTAL_PRICE", jsonObject2.getString("data1[TOTAL_PRICE]"));
                                                billroom.put("STATE", "eda58d7280554dd9918207d27e2d4654");//已收款
                                                billroom.put("PRICE_TYPE", "0");//不是收入支出了  是 买卡 和消费
                                                if (jsonObject2.containsKey("data1[PART_START" + part + "]")) {
                                                    billroom.put("PART_START", jsonObject2.getString("data1[PART_START" + part + "]"));
                                                }
                                                if (jsonObject2.containsKey("data1[PART_END" + part + "]")) {
                                                    billroom.put("PART_END", jsonObject2.getString("data1[PART_END" + part + "]"));
                                                }
                                            }
                                        }
                                    } else {
                                        billroom.put("STATE", "682177ade393478e8224f9a3aa385a6c");//未收款
                                        billroom.put("CHECK_STATE", "0");//手动添加账单 暂时归到 待审核中
                                        billroom.put("PRICE_TYPE", jsonObject2.getString("data1[PRICE_TYPE" + part + "]"));//收入 支出
                                    }
                                    if (jsonObject2.containsKey("data1[ALLOT_BILL" + part + "")) {
                                        billroom.put("ALLOT_BILL", jsonObject2.getString("data1[ALLOT_BILL" + part + "]"));//公户 私户
                                    }
                                    billroom.put("MAKE_BILL_TYPE", "1");//手动添加
                                    billService.save(billroom);

                                    //杂费附件
                                    if (jsonObject2.containsKey("data1[ATTACHMENT][0][name]")) {
                                        PageData pds = new PageData();
                                        pds.put("ID", this.get32UUID());    //主键
                                        pds.put("OID", zaid);
                                        pds.put("NAME", pd.get("data1[ATTACHMENT][0][name]"));
                                        pds.put("EXT", pd.get("data1[ATTACHMENT][0][ext]"));
                                        pds.put("PATH", pd.get("data1[ATTACHMENT][0][url]"));
                                        pds.put("TYPE", "bill");
                                        pds.put("SORT", "1");
                                        pds.put("REMARK", "");
                                        pds.put("CREATE_TIME", new DateUtil().getTime());
                                        pds.put("CREATE_ID", user.getUSER_ID());
                                        pds.put("IS_DELETED", 0);
                                        attachmentService.saveAttachment(pds);
                                    }

                                    //保存操作记录
                                    PageData oppd = new PageData();
                                    oppd.put("ID", this.get32UUID());    //主键
                                    oppd.put("IS_DEL", 0); //是否删除
                                    oppd.put("SORT", 0); //排序
                                    oppd.put("BILL_ID", zaid); //排序
                                    oppd.put("CREATE_ID", user.getUSER_ID()); //创建用户
                                    oppd.put("CREATE_DATE", new DateUtil().getTime()); //创建时间
                                    //oppd.put("DETAILS","新增一个"+pd.get("BILL_NAME").toString()+"账单,金额"+pd.get("TOTAL_PRICE").toString());
                                    oppd.put("DETAILS", "新增一个账单");
                                    oppd.put("OPERA_TIME", new DateUtil().getTime());
                                    oppd.put("OPERATOR", user.getNAME());
                                    recordService.save(oppd);
                                }
                            }
                        }

                        //sb.append("="+jsonObject.getString(key));
                    }
                } catch (JSONException e) {
                    e.printStackTrace();
                }

            }


            PageData pds = new PageData();
            //JSONObject jo = (JSONObject) ATTACHMENT.get(i);
            pds.put("ID", this.get32UUID());    //主键
            pds.put("OID", BID);
            pds.put("NAME", pd.get("data1[ATTACHMENT][0][name]"));
            pds.put("EXT", pd.get("data1[ATTACHMENT][0][ext]"));
            pds.put("PATH", pd.get("data1[ATTACHMENT][0][url]"));
            pds.put("TYPE", "bill");
            pds.put("SORT", "1");
            pds.put("REMARK", "");
            pds.put("CREATE_TIME", new DateUtil().getTime());
            pds.put("CREATE_ID", user.getUSER_ID());
            pds.put("IS_DELETED", 0);


            res.put("data", "");
            res.put("errcode", "0");
            res.put("errmsg", "ok");
        } catch (Exception e) {
            logger.error(e.toString(), e);
            res.put("data", "");
            res.put("errcode", "1");
            res.put("errmsg", e.toString());
        }
        return res;
    }


    /**
     * 返回list 账单 未付款 列表
     */
    @RequestMapping(value = "/json")
    @ResponseBody
    public Object json(Page page) {
        PageData pd = new PageData();
        Map<String, Object> map = new HashMap<String, Object>();
        List<PageData> varList;
        String datalayui = null;
        try {
            pd = this.getPageData();
            getPData(page, pd);
            varList = billService.list(page);
            datalayui = getLData(page, varList);
        } catch (Exception e) {
            logger.error(e.toString(), e);
        } finally {
            logAfter(logger);
        }
        return datalayui;
    }

    /**
     * 返回审批事项 账单审核列表
     */
    @RequestMapping(value = "/billshenhe")
    @ResponseBody
    public Object billshenhe(Page page) {
        PageData pd = new PageData();
        Map<String, Object> map = new HashMap<String, Object>();
        List<PageData> varList;
        String datalayui = null;
        pd = this.getPageData();
        //获取当前登录用户
        Subject currentUser = SecurityUtils.getSubject();
        Session session = currentUser.getSession();
        User user = (User) session.getAttribute(Const.SESSION_USER);
        try {
            pd.put("USER_ID", user.getUSER_ID());
            PageData dataAuth = roleService.authListByLoginUser(pd);
            pd = this.getPageData();
            List<String> dataList = new ArrayList<>();
            if (!"95bb91515192430bb7a6b5d0a0876542".equals(user.getUSER_TYPE())) {
                String dataStr = "(";
                if (dataAuth.get("AUTH_CODE").toString().indexOf("SHQXZD_1") != -1) {
                    //一级权限
                    dataStr += "\"01\",";
                }
                if (dataAuth.get("AUTH_CODE").toString().indexOf("SHQXZD_2") != -1) {
                    //二级权限
                    dataStr += "\"02\",";
                }
                if (dataAuth.get("AUTH_CODE").toString().indexOf("SHQXZD_3") != -1) {
                    //三级权限
                    dataStr += "\"03\",";
                }
                if (dataAuth.get("AUTH_CODE").toString().indexOf("SHQXZD_4") != -1) {
                    //四级权限
                    dataStr += "\"04\",";
                }
                dataStr += "\"-1\")";
                pd.put("CHECK_STATE", dataStr);
            }
            getPData(page, pd);
            varList = billService.billshenhelist(page);
            datalayui = getLData(page, varList);
        } catch (Exception e) {
            logger.error(e.toString(), e);
        } finally {
            logAfter(logger);
        }
        return datalayui;
    }

    /**
     * 返回费用管理 -审批账单  账单审核列表
     */
    @RequestMapping(value = "/billshenpi")
    @ResponseBody
    public Object billshenpi(Page page) {
        PageData pd = new PageData();
        Map<String, Object> map = new HashMap<String, Object>();
        List<PageData> varList;
        String datalayui = null;
        try {
            pd = this.getPageData();
            getPData(page, pd);
            varList = billService.billshenpi(page);
            datalayui = getLData(page, varList);
        } catch (Exception e) {
            logger.error(e.toString(), e);
        } finally {
            logAfter(logger);
        }
        return datalayui;
    }

    /**
     *  正在审批中的账单 取消操作
     */
    @RequestMapping(value = "/cancelShenpi")
    @ResponseBody
    public PageData cancelShenpi() {
        logBefore(logger, "取消审批账单");
        PageData res = new PageData();
        PageData pd = this.getPageData();

        try {
            //fixme 审核中的账单不能有取消
            pd.put("CHECK_STATE", "1");
            billService.shenhebill(pd);
            res.put("data", "");
            res.put("errcode", "0");
            res.put("errmsg", "ok");
        } catch (Exception e) {
            logger.error(e.toString(), e);
            res.put("data", "");
            res.put("errcode", "1");
            res.put("errmsg", e.toString());
        }

        return res;
    }

    /**
     * 返回list 账单  已处理 已付款 列表
     */
    @RequestMapping(value = "/listPayOk")
    @ResponseBody
    public Object listPayOk(Page page) {
        PageData pd = new PageData();
        Map<String, Object> map = new HashMap<String, Object>();
        List<PageData> varList;
        String datalayui = null;
        try {
            pd = this.getPageData();
            getPData(page, pd);
            varList = billService.listPayOk(page);
            datalayui = getLData(page, varList);
        } catch (Exception e) {
            logger.error(e.toString(), e);
        } finally {
            logAfter(logger);
        }
        return datalayui;
    }

    /**
     * 返回list 账单 应付 列表
     */
    @RequestMapping(value = "/listyingfu")
    @ResponseBody
    public Object listyingfu(Page page) {
        PageData pd = new PageData();
        Map<String, Object> map = new HashMap<String, Object>();
        List<PageData> varList;
        String datalayui = null;
        try {
            pd = this.getPageData();
            getPData(page, pd);
            varList = billService.listyingfu(page);
            datalayui = getLData(page, varList);
        } catch (Exception e) {
            logger.error(e.toString(), e);
        } finally {
            logAfter(logger);
        }
        return datalayui;
    }

    /**
     * 返回list 账单 逾期 列表
     */
    @RequestMapping(value = "/listPayyuqi")
    @ResponseBody
    public Object listPayyuqi(Page page) {
        PageData pd = new PageData();
        Map<String, Object> map = new HashMap<String, Object>();
        List<PageData> varList;
        String datalayui = null;
        try {
            pd = this.getPageData();
            getPData(page, pd);
            varList = billService.listPayyuqi(page);
            datalayui = getLData(page, varList);
        } catch (Exception e) {
            logger.error(e.toString(), e);
        } finally {
            logAfter(logger);
        }
        return datalayui;
    }

    /**
     * 扫描逾期账单 返回后 增加到 消息通知
     */
    @RequestMapping(value = "/billyuqimessage")
    @ResponseBody
    public PageData billyuqimessage() {
        logBefore(logger, "Building列表");
        PageData res = new PageData();
        PageData pd = this.getPageData();
        try {
            List<Map<String, Object>> datas = (List<Map<String, Object>>) billService.billyuqimessage();
            /*if(list.size()>0){
                res.put("data", list);
            }*/
            res.put("errcode", "0");
            res.put("errmsg", "ok");
        } catch (Exception e) {
            logger.error(e.toString(), e);
            res.put("data", "");
            res.put("errcode", "1");
            res.put("errmsg", e.toString());
        }
        return res;
    }

    /**
     * 返回list 账单 自用 列表
     */
    @RequestMapping(value = "/listPayziyong")
    @ResponseBody
    public Object listPayziyong(Page page) {
        PageData pd = new PageData();
        Map<String, Object> map = new HashMap<String, Object>();
        List<PageData> varList;
        String datalayui = null;
        try {
            pd = this.getPageData();
            getPData(page, pd);
            varList = billService.listPayziyong(page);
            datalayui = getLData(page, varList);
        } catch (Exception e) {
            logger.error(e.toString(), e);
        } finally {
            logAfter(logger);
        }
        return datalayui;
    }

    /**
     * 返回list 账单 自用 房间弹出层 列表
     */
    @RequestMapping(value = "/listPayziyongRoom")
    @ResponseBody
    public Object listPayziyongRoom(Page page) {
        PageData pd = new PageData();
        Map<String, Object> map = new HashMap<String, Object>();
        List<PageData> varList;
        String datalayui = null;
        try {
            pd = this.getPageData();
            getPData(page, pd);
            varList = billService.listPayziyongRoom(page);
            datalayui = getLData(page, varList);
        } catch (Exception e) {
            logger.error(e.toString(), e);
        } finally {
            logAfter(logger);
        }
        return datalayui;
    }

    /**
     * 返回list 账单 未来 列表
     */
    @RequestMapping(value = "/listPayNext")
    @ResponseBody
    public Object listPayNext(Page page) {
        PageData pd = new PageData();
        Map<String, Object> map = new HashMap<String, Object>();
        List<PageData> varList;
        String datalayui = null;
        try {
            pd = this.getPageData();
            getPData(page, pd);
            varList = billService.listPayNext(page);
            datalayui = getLData(page, varList);
        } catch (Exception e) {
            logger.error(e.toString(), e);
        } finally {
            logAfter(logger);
        }
        return datalayui;
    }

    /**
     * 返回list 流水明细 收入 列表
     */
    @RequestMapping(value = "/listshouru")
    @ResponseBody
    public Object listshouru(Page page) {
        PageData pd = new PageData();
        Map<String, Object> map = new HashMap<String, Object>();
        List<PageData> varList;
        String datalayui = null;
        try {
            pd = this.getPageData();
            pd.put("PRICE_TYPE", "0");//查类型 为收入的
            getPData(page, pd);
            varList = billService.listshouru(page);
            datalayui = getLData(page, varList);
        } catch (Exception e) {
            logger.error(e.toString(), e);
        } finally {
            logAfter(logger);
        }
        return datalayui;
    }

    /**
     * 返回list 交易明细
     */
    @RequestMapping(value = "/listjymx")
    @ResponseBody
    public Object listjymx(Page page) {
        PageData pd = new PageData();
        Map<String, Object> map = new HashMap<String, Object>();
        List<PageData> varList;
        String datalayui = null;
        try {
            pd = this.getPageData();
            //pd.put("PRICE_TYPE","0");//查类型 为收入的
            getPData(page, pd);
            varList = billService.listjymx(page);
            datalayui = getLData(page, varList);
        } catch (Exception e) {
            logger.error(e.toString(), e);
        } finally {
            logAfter(logger);
        }
        return datalayui;
    }

    /**
     * 返回list 流水明细 支出 列表
     */
    @RequestMapping(value = "/listzhichu")
    @ResponseBody
    public Object listzhichu(Page page) {
        PageData pd = new PageData();
        Map<String, Object> map = new HashMap<String, Object>();
        List<PageData> varList;
        String datalayui = null;
        try {
            pd = this.getPageData();
            pd.put("PRICE_TYPE", "1");//查类型 为支出的
            getPData(page, pd);
            varList = billService.listshouru(page);
            datalayui = getLData(page, varList);
        } catch (Exception e) {
            logger.error(e.toString(), e);
        } finally {
            logAfter(logger);
        }
        return datalayui;
    }

    /**
     * 返回res data bill_pay  json
     */
    @RequestMapping(value = "/listbilljson")
    @ResponseBody
    public PageData listbilljson() {
        logBefore(logger, "Building列表");
        PageData res = new PageData();
        PageData pd = this.getPageData();
        try {
            List<PageData> list = billService.listbilljson(pd);
            if (list.size() > 0) {
                res.put("data", list.get(0));
            }
            res.put("errcode", "0");
            res.put("errmsg", "ok");
        } catch (Exception e) {
            logger.error(e.toString(), e);
            res.put("data", "");
            res.put("errcode", "1");
            res.put("errmsg", e.toString());
        }
        return res;
    }

    /**
     * 返回list 收入预算
     */
    @RequestMapping(value = "/listshouruyusuan")
    @ResponseBody
    public Object listshouruyusuan(Page page) {
        PageData pd = new PageData();
        Map<String, Object> map = new HashMap<String, Object>();
        List<PageData> varList;
        String datalayui = null;
        try {
            pd = this.getPageData();
            getPData(page, pd);
            varList = billService.listshouruyusuan(page);
            datalayui = getLData(page, varList);
        } catch (Exception e) {
            logger.error(e.toString(), e);
        } finally {
            logAfter(logger);
        }
        return datalayui;
    }

    /**
     * 返回 退租结算账单
     */
    @RequestMapping(value = "/listtzjs")
    @ResponseBody
    public Object listtzjs(Page page) {
        PageData pd = new PageData();
        Map<String, Object> map = new HashMap<String, Object>();
        List<PageData> varList;
        String datalayui = null;
        try {
            pd = this.getPageData();
            getPData(page, pd);
            varList = billService.listtzjs(page);
            datalayui = getLData(page, varList);
        } catch (Exception e) {
            logger.error(e.toString(), e);
        } finally {
            logAfter(logger);
        }
        return datalayui;
    }

    /**
     * 新增账单  临时性消费
     */
    @RequestMapping(value = "/saveInterim")
    @ResponseBody
    public PageData saveInterim(){
        //获取当前用户
        Subject currentUser = SecurityUtils.getSubject();
        Session session = currentUser.getSession();
        User user = (User) session.getAttribute(Const.SESSION_USER);
        PageData res = new PageData();
        PageData pd = this.getPageData();
        try {
            JSONObject jsonObject2 = JSONObject.fromObject(pd);

            List<PageData> list = (List<PageData>) JSONArray.toList(JSONArray.fromObject(jsonObject2.get("sendData[DATA]").toString()), PageData.class);

            List<PageData> uploadList = (List<PageData>) JSONArray.toList(JSONArray.fromObject(jsonObject2.get("uploadData[DATA]").toString()), PageData.class);
            for (PageData pdData : list) {
                PageData billroom = new PageData();//创建新账单 如果房间存在合同 就在合同中增加账单 如果不存在合同 添加无合同账单
                String zuid = this.get32UUID();
                billroom.put("STATE", "eda58d7280554dd9918207d27e2d4654");//已收款
                billroom.put("ROOM_ID", pdData.getString("ROOMID"));//停车场多选房间
                List<PageData> bills = billService.isHaveContract(billroom);
                billroom.put("CHECK_STATE", "1");//手动添加账单 暂时归到 待审核中
                billroom.put("DB_TYPE", "1");   //1账单
                billroom.put("PARK_CARD", pdData.getString("PARK_CARD"));
                billroom.put("PRICE_TYPE", "3");// 临时性消费
                billroom.put("MAKE_BILL_TYPE", "1");//手动添加
                billroom.put("ROOM_ID", pdData.getString("ROOMID"));//停车场多选房间
                billroom.put("ALLOT_BILL", pdData.getString("ALLOT_BILL"));
                billroom.put("IS_DEL", "0");
                billroom.put("BILL_TYPE", "2");
                billroom.put("BILL_NAME", "停车费");
                billroom.put("INFO", pdData.getString("INFO"));
                billroom.put("PARK_ID", pdData.getString("PARK_ID"));
                billroom.put("CREATE_ID", user.getUSER_ID());
                billroom.put("CREATE_DATE", DateUtil.getTime());
                billroom.put("UPDATE_DATE", DateUtil.getTime());
                billroom.put("UPDATE_ID", user.getUSER_ID());

                if( pdData.containsKey("PART_START")){
                    billroom.put("PART_START",pdData.getString("PART_START"));
                }
                if( pdData.containsKey("PART_END")){
                    billroom.put("PART_END",pdData.getString("PART_END"));
                }
                billroom.put("ID", zuid);
                if (bills.size() > 0) {
                    billroom.put("CONTRACT_ID", bills.get(0).getString("CONTRACT_ID"));
                } else {
                    billroom.put("CONTRACT_ID", "-");
                }



                if ("0".equals(pdData.getString("PRICE_TYPE"))) {// 0卡  1收入
                    billroom.put("ROOM_ID", pdData.get("ROOMID").toString());
                    billroom.put("TOTAL_PRICE", "");//消费的时候 不存price
                    billroom.put("PARK_CARD",  pdData.getString("PARK_CARD"));
                    billroom.put("ALLOT_BILL", "");

                } else {//收入的时候 存现金账户
                    billroom.put("TOTAL_PRICE", pdData.getString("ROOM_MONEY"));
                    billroom.put("ALLOT_BILL", pdData.getString("ALLOT_BILL"));
                    billroom.put("PARK_CARD", "");
                    billroom.put("ROOM_ID","");

                }




                billService.save(billroom);
                saveUpload(zuid, uploadList, user);
                saveJilu(zuid,user);

            }


            res.put("data", "");
            res.put("errcode", "0");
            res.put("errmsg", "ok");
        } catch (Exception e) {
            logger.error(e.toString(), e);
            res.put("data", "");
            res.put("errcode", "1");
            res.put("errmsg", e.toString());
        }

        return res;
    }




    /**
     * 新增账单
     */
    @RequestMapping(value = "/saveTCar")
    @ResponseBody
    public PageData saveTCar() {
        //获取当前用户
        Subject currentUser = SecurityUtils.getSubject();
        Session session = currentUser.getSession();
        User user = (User) session.getAttribute(Const.SESSION_USER);
        PageData res = new PageData();
        PageData pd = this.getPageData();
        try {
            JSONObject jsonObject2 = JSONObject.fromObject(pd);

            List<PageData> list = (List<PageData>) JSONArray.toList(JSONArray.fromObject(jsonObject2.get("sendData[DATA]").toString()), PageData.class);

            List<PageData> uploadList = (List<PageData>) JSONArray.toList(JSONArray.fromObject(jsonObject2.get("uploadData[DATA]").toString()), PageData.class);
            for (PageData pdData : list) {
                PageData billroom = new PageData();//创建新账单 如果房间存在合同 就在合同中增加账单 如果不存在合同 添加无合同账单
                String zuid = this.get32UUID();
                billroom.put("ROOM_ID", pdData.get("ROOMID").toString());
                List<PageData> bills = billService.isHaveContract(billroom);
                billroom.put("STATE", "eda58d7280554dd9918207d27e2d4654");//已收款
                billroom.put("CHECK_STATE", "1");//手动添加账单 暂时归到 待审核中
                billroom.put("DB_TYPE", "1");   //1账单
                billroom.put("PARK_CARD", pdData.getString("PARK_CARD"));
                billroom.put("PRICE_TYPE", pdData.getString("PRICE_TYPE"));// 买卡
                billroom.put("MAKE_BILL_TYPE", "1");//手动添加
                billroom.put("ROOM_ID", pdData.getString("ROOMID"));//停车场多选房间
                billroom.put("ALLOT_BILL", pdData.getString("ALLOT_BILL"));
                billroom.put("IS_DEL", "0");
                billroom.put("BILL_TYPE", "2");
                billroom.put("BILL_NAME", "停车费");
                billroom.put("TOTAL_PRICE", pdData.get("ROOM_MONEY"));
                billroom.put("INFO", pdData.getString("INFO"));
                billroom.put("PARK_ID", pdData.getString("PARK_ID"));
                billroom.put("CREATE_ID", user.getUSER_ID());
                billroom.put("CREATE_DATE", DateUtil.getTime());
                billroom.put("UPDATE_DATE", DateUtil.getTime());
                billroom.put("UPDATE_ID", user.getUSER_ID());

                if( pdData.containsKey("PART_START")){
                    billroom.put("PART_START",pdData.getString("PART_START"));
                }
                if( pdData.containsKey("PART_END")){
                    billroom.put("PART_END",pdData.getString("PART_END"));
                }
                billroom.put("ID", zuid);
                if (bills.size() > 0) {
                    billroom.put("CONTRACT_ID", bills.get(0).getString("CONTRACT_ID"));
                } else {
                    billroom.put("CONTRACT_ID", "-");
                }


                billService.save(billroom);
                saveUpload(zuid, uploadList, user);
                saveJilu(zuid,user);

            }


            res.put("data", "");
            res.put("errcode", "0");
            res.put("errmsg", "ok");
        } catch (Exception e) {
            logger.error(e.toString(), e);
            res.put("data", "");
            res.put("errcode", "1");
            res.put("errmsg", e.toString());
        }

        return res;
    }



    public void saveJilu(String Id, User user){
        //保存操作记录
        try {
        PageData oppd = new PageData();
        oppd.put("ID", this.get32UUID());    //主键
        oppd.put("IS_DEL", 0); //是否删除
        oppd.put("SORT", 0); //排序
        oppd.put("BILL_ID", Id); //排序
        oppd.put("CREATE_ID", user.getUSER_ID()); //创建用户
        oppd.put("CREATE_DATE", new DateUtil().getTime()); //创建时间
        //oppd.put("DETAILS","新增一个"+pd.get("BILL_NAME").toString()+"账单,金额"+pd.get("TOTAL_PRICE").toString());
        oppd.put("DETAILS", "新增一个账单");
        oppd.put("OPERA_TIME", new DateUtil().getTime());
        oppd.put("OPERATOR", user.getNAME());
        recordService.save(oppd);
        } catch (Exception e) {
            logger.error(e.toString(), e);

        }
    }


    public void saveUpload(String Id, List<PageData> list, User user) {
        //
        try {
            for (PageData pd : list) {
                PageData pds = new PageData();
                pds.put("ID", this.get32UUID());    //主键
                pds.put("OID", Id);
                pds.put("NAME", pd.get("name"));
                pds.put("EXT", pd.get("ext"));
                pds.put("PATH", pd.get("url"));
                pds.put("TYPE", "bill");
                pds.put("SORT", "1");
                pds.put("REMARK", "");
                pds.put("CREATE_TIME", new DateUtil().getTime());
                pds.put("CREATE_ID", user.getUSER_ID());
                pds.put("IS_DELETED", 0);
                attachmentService.saveAttachment(pds);
            }

        } catch (Exception e) {
            logger.error(e.toString(), e);

        }

    }


    /**
     * 新增账单
     */
    @RequestMapping(value = "/save")
    @ResponseBody
    public PageData save() {
        DefaultTransactionDefinition defaultTransactionDefinition = new DefaultTransactionDefinition();
        defaultTransactionDefinition.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRED);
        TransactionStatus status = transactionManager.getTransaction(defaultTransactionDefinition);
        logBefore(logger, "新增账单");
        PageData res = new PageData();
        PageData pd = this.getPageData();
        //获取当前登录用户
        Subject currentUser = SecurityUtils.getSubject();
        Session session = currentUser.getSession();
        User user = (User) session.getAttribute(Const.SESSION_USER);
        try {
            //JSONArray jsonArray=JSONArray.fromObject(pd);
            //获得jsonArray的第一个元素
            //Object o=jsonArray.get(0);
            JSONObject jsonObject2 = JSONObject.fromObject(pd);
            //JSONHelper.json2Map(jsonObject2.get("sendData[DATA]").toString());
            Map map1 = JSONHelper.json2Map(jsonObject2.get("sendData[DATA]").toString());
            List<PageData> billlist = propertyService.listAllPro(pd);//获取所有账单类型
            Set<Object> keySet = map1.keySet();
            //有了Set集合。就可以获取其迭代器。
            Iterator<Object> it = keySet.iterator();
            //租金id
            String BID = this.get32UUID();
            int part = 0;//统计杂费第几个paet
            int zujinyajin = 1;//统计杂费第几个paet
            Object key = it.next();
            //有了键可以通过map集合的get方法获取其对应的值。
            Object value = (Object) map1.get(key);
            //System.out.println(value.toString());
            List<PageData> list2 = (List<PageData>) JSONArray.toList(JSONArray.fromObject(value.toString()), PageData.class);
            for (PageData stu : list2) {
                PageData billroom = new PageData();//创建新账单 如果房间存在合同 就在合同中增加账单 如果不存在合同 添加无合同账单
                billroom.put("ROOM_ID", stu.get("ROOM_ID").toString());
                List<PageData> ishavecontract = billService.isHaveContract(billroom);
                if (ishavecontract.size() > 0) {
                    billroom.put("CONTRACT_ID", ishavecontract.get(0).get("CONTRACT_ID").toString());
                }
                //version 1 暂时写死

                if (jsonObject2.containsKey("data1[租金]")) {
                    String zuid = this.get32UUID();
                    billroom.put("ID", zuid);
                    billroom.put("CREATE_ID", user.getUSER_ID());
                    billroom.put("CREATE_DATE", DateUtil.getTime());
                    billroom.put("UPDATE_DATE", DateUtil.getTime());//
                    billroom.put("UPDATE_ID", user.getUSER_ID()); //
                    billroom.put("SORT", "0");
                    billroom.put("IS_DEL", "0");
                    billroom.put("BILL_SIGNER", jsonObject2.getString("data1[BILL_SIGNER]").toString());
                    billroom.put("START_DATE", jsonObject2.getString("data1[START_DATE]"));
                    billroom.put("END_DATE", jsonObject2.getString("data1[END_DATE]"));
                    billroom.put("PAY_DATE", jsonObject2.getString("data1[PAY_DATE]"));
                    billroom.put("ROOM_ID", stu.get("ROOM_ID").toString());
                    billroom.put("BILL_NAME", jsonObject2.getString("data1[zujin]"));
                    billroom.put("BILL_TYPE", jsonObject2.getString("data1[PRICE_TYPE1]"));//增加租金类型 应该支出的
                    billroom.put("TOTAL_PRICE", jsonObject2.getString("data1[租金]"));
                    billroom.put("INFO", jsonObject2.getString("data1[INFO]"));
                    billroom.put("STATE", "682177ade393478e8224f9a3aa385a6c");
                    billroom.put("CHECK_STATE", "01");//手动添加账单 暂时归到 待审核中
                    billroom.put("MAKE_BILL_TYPE", "1");//手动添加
                    billroom.put("PRICE_TYPE", jsonObject2.getString("data1[PRICE_TYPE1]"));//支出  收入
                    billroom.put("ALLOT_BILL", jsonObject2.getString("data1[ALLOT_BILL1]"));//公户 私户
                    billService.save(billroom);
                    //租金附件
                    if (jsonObject2.containsKey("data1[ATTACHMENT][0][name]")) {
                        PageData pds = new PageData();
                        pds.put("ID", this.get32UUID());    //主键
                        pds.put("OID", zuid);
                        pds.put("NAME", pd.get("data1[ATTACHMENT][0][name]"));
                        pds.put("EXT", pd.get("data1[ATTACHMENT][0][ext]"));
                        pds.put("PATH", pd.get("data1[ATTACHMENT][0][url]"));
                        pds.put("TYPE", "bill");
                        pds.put("SORT", "1");
                        pds.put("REMARK", "");
                        pds.put("CREATE_TIME", new DateUtil().getTime());
                        pds.put("CREATE_ID", user.getUSER_ID());
                        pds.put("IS_DELETED", 0);
                        attachmentService.saveAttachment(pds);
                    }
                    //保存操作记录
                    PageData oppd = new PageData();
                    oppd.put("ID", this.get32UUID());    //主键
                    oppd.put("IS_DEL", 0); //是否删除
                    oppd.put("SORT", 0); //排序
                    oppd.put("BILL_ID", zuid); //排序
                    oppd.put("CREATE_ID", user.getUSER_ID()); //创建用户
                    oppd.put("CREATE_DATE", new DateUtil().getTime()); //创建时间
                    //oppd.put("DETAILS","新增一个"+pd.get("BILL_NAME").toString()+"账单,金额"+pd.get("TOTAL_PRICE").toString());
                    oppd.put("DETAILS", "新增一个账单");
                    oppd.put("OPERA_TIME", new DateUtil().getTime());
                    oppd.put("OPERATOR", user.getNAME());
                    recordService.save(oppd);

                }
                //同时添加 多个 租金的处理方法
                for (int i = 1; i < pd.size(); i++) {
                    if (jsonObject2.containsKey("data1[租金" + i + "]")) {
                        String zuid = this.get32UUID();
                        billroom.put("ID", zuid);
                        billroom.put("CREATE_ID", user.getUSER_ID());
                        billroom.put("CREATE_DATE", DateUtil.getTime());
                        billroom.put("UPDATE_DATE", DateUtil.getTime());
                        billroom.put("UPDATE_ID", user.getUSER_ID());
                        billroom.put("SORT", "0");
                        billroom.put("IS_DEL", "0");
                        billroom.put("BILL_SIGNER", jsonObject2.getString("data1[BILL_SIGNER]").toString());
                        billroom.put("START_DATE", jsonObject2.getString("data1[START_DATE]"));
                        billroom.put("END_DATE", jsonObject2.getString("data1[END_DATE]"));
                        billroom.put("PAY_DATE", jsonObject2.getString("data1[PAY_DATE]"));
                        billroom.put("ROOM_ID", stu.get("ROOM_ID").toString());
                        billroom.put("BILL_TYPE", jsonObject2.getString("data1[PRICE_TYPE" + i + "]"));//增加租金类型
                        billroom.put("BILL_NAME", jsonObject2.getString("data1[zujin]"));
                        billroom.put("TOTAL_PRICE", jsonObject2.getString("data1[租金" + i + "]"));
                        billroom.put("INFO", jsonObject2.getString("data1[INFO]"));
                        billroom.put("STATE", "682177ade393478e8224f9a3aa385a6c");
                        billroom.put("CHECK_STATE", "01");//手动添加账单 暂时归到 待审核中
                        billroom.put("MAKE_BILL_TYPE", "1");//手动添加
                        billroom.put("PRICE_TYPE", jsonObject2.getString("data1[PRICE_TYPE" + i + "]"));//支出  收入
                        billroom.put("ALLOT_BILL", jsonObject2.getString("data1[ALLOT_BILL" + i + "]"));//公户 私户
                        billService.save(billroom);
                        //保存操作记录
                        PageData oppd = new PageData();
                        oppd.put("ID", this.get32UUID());    //主键
                        oppd.put("IS_DEL", 0); //是否删除
                        oppd.put("SORT", 0); //排序
                        oppd.put("BILL_ID", zuid); //排序
                        oppd.put("CREATE_ID", user.getUSER_ID()); //创建用户
                        oppd.put("CREATE_DATE", new DateUtil().getTime()); //创建时间
                        //oppd.put("DETAILS","新增一个"+pd.get("BILL_NAME").toString()+"账单,金额"+pd.get("TOTAL_PRICE").toString());
                        oppd.put("DETAILS", "新增一个账单");
                        oppd.put("OPERA_TIME", new DateUtil().getTime());
                        oppd.put("OPERATOR", user.getNAME());
                        recordService.save(oppd);
                    }
                }


                if (jsonObject2.containsKey("data1[押金]")) {
                    String yaid = this.get32UUID();
                    billroom.put("ID", yaid);
                    billroom.put("CREATE_ID", user.getUSER_ID());
                    billroom.put("CREATE_DATE", DateUtil.getTime());
                    billroom.put("UPDATE_DATE", DateUtil.getTime());
                    billroom.put("UPDATE_ID", user.getUSER_ID());
                    billroom.put("SORT", "0");
                    billroom.put("IS_DEL", "0");
                    billroom.put("BILL_SIGNER", jsonObject2.getString("data1[BILL_SIGNER]").toString());
                    billroom.put("START_DATE", jsonObject2.getString("data1[START_DATE]"));
                    billroom.put("END_DATE", jsonObject2.getString("data1[END_DATE]"));
                    billroom.put("PAY_DATE", jsonObject2.getString("data1[PAY_DATE]"));
                    billroom.put("ROOM_ID", stu.get("ROOM_ID").toString());
                    billroom.put("BILL_TYPE", 1);//增加押金类型
                    billroom.put("BILL_NAME", jsonObject2.getString("data1[yajin]"));
                    billroom.put("TOTAL_PRICE", jsonObject2.getString("data1[押金]"));
                    billroom.put("INFO", jsonObject2.getString("data1[INFO]"));
                    billroom.put("STATE", "682177ade393478e8224f9a3aa385a6c");
                    billroom.put("CHECK_STATE", "01");//手动添加账单 暂时归到 待审核中
                    billroom.put("ALLOT_BILL", "0");//公户 私户
                    billroom.put("MAKE_BILL_TYPE", "1");//手动添加
                    billroom.put("PRICE_TYPE", jsonObject2.getString("data1[PRICE_TYPE1]"));//支出  收入
                    billService.save(billroom);
                    //押金附件
                    if (jsonObject2.containsKey("data1[ATTACHMENT][0][name]")) {
                        PageData pds = new PageData();
                        pds.put("ID", this.get32UUID());    //主键
                        pds.put("OID", yaid);
                        pds.put("NAME", pd.get("data1[ATTACHMENT][0][name]"));
                        pds.put("EXT", pd.get("data1[ATTACHMENT][0][ext]"));
                        pds.put("PATH", pd.get("data1[ATTACHMENT][0][url]"));
                        pds.put("TYPE", "bill");
                        pds.put("SORT", "1");
                        pds.put("REMARK", "");
                        pds.put("CREATE_TIME", new DateUtil().getTime());
                        pds.put("CREATE_ID", user.getUSER_ID());
                        pds.put("IS_DELETED", 0);
                        attachmentService.saveAttachment(pds);
                    }
                    //保存操作记录
                    PageData oppd = new PageData();
                    oppd.put("ID", this.get32UUID());    //主键
                    oppd.put("IS_DEL", 0); //是否删除
                    oppd.put("SORT", 0); //排序
                    oppd.put("BILL_ID", yaid); //排序
                    oppd.put("CREATE_ID", user.getUSER_ID()); //创建用户
                    oppd.put("CREATE_DATE", new DateUtil().getTime()); //创建时间
                    //oppd.put("DETAILS","新增一个"+pd.get("BILL_NAME").toString()+"账单,金额"+pd.get("TOTAL_PRICE").toString());
                    oppd.put("DETAILS", "新增一个账单");
                    oppd.put("OPERA_TIME", new DateUtil().getTime());
                    oppd.put("OPERATOR", user.getNAME());
                    recordService.save(oppd);
                }

                //同时添加 多个 押金的处理方法
                for (int i = 1; i < pd.size(); i++) {
                    if (jsonObject2.containsKey("data1[押金" + i + "]")) {
                        zujinyajin++;
                        String yaid = this.get32UUID();
                        billroom.put("ID", yaid);
                        billroom.put("CREATE_ID", user.getUSER_ID());
                        billroom.put("CREATE_DATE", DateUtil.getTime());
                        billroom.put("UPDATE_DATE", DateUtil.getTime());
                        billroom.put("UPDATE_ID", user.getUSER_ID());
                        billroom.put("SORT", "0");
                        billroom.put("IS_DEL", "0");
                        billroom.put("BILL_SIGNER", jsonObject2.getString("data1[BILL_SIGNER]").toString());
                        billroom.put("START_DATE", jsonObject2.getString("data1[START_DATE]"));
                        billroom.put("END_DATE", jsonObject2.getString("data1[END_DATE]"));
                        billroom.put("PAY_DATE", jsonObject2.getString("data1[PAY_DATE]"));
                        billroom.put("ROOM_ID", stu.get("ROOM_ID").toString());
                        billroom.put("BILL_TYPE", 1);//增加押金类型
                        billroom.put("BILL_NAME", jsonObject2.getString("data1[yajin]"));
                        billroom.put("TOTAL_PRICE", jsonObject2.getString("data1[押金" + zujinyajin + "]"));
                        billroom.put("INFO", jsonObject2.getString("data1[INFO]"));
                        billroom.put("STATE", "682177ade393478e8224f9a3aa385a6c");
                        billroom.put("CHECK_STATE", "01");//手动添加账单 暂时归到 待审核中
                        billroom.put("MAKE_BILL_TYPE", "1");//手动添加
                        billroom.put("PRICE_TYPE", jsonObject2.getString("data1[PRICE_TYPE" + zujinyajin + "]"));//支出  收入
                        billroom.put("ALLOT_BILL", jsonObject2.getString("data1[ALLOT_BILL" + zujinyajin + "]"));//公户 私户
                        billService.save(billroom);
                        //保存操作记录
                        PageData oppd = new PageData();
                        oppd.put("ID", this.get32UUID());    //主键
                        oppd.put("IS_DEL", 0); //是否删除
                        oppd.put("SORT", 0); //排序
                        oppd.put("BILL_ID", yaid); //排序
                        oppd.put("CREATE_ID", user.getUSER_ID()); //创建用户
                        oppd.put("CREATE_DATE", new DateUtil().getTime()); //创建时间
                        //oppd.put("DETAILS","新增一个"+pd.get("BILL_NAME").toString()+"账单,金额"+pd.get("TOTAL_PRICE").toString());
                        oppd.put("DETAILS", "新增一个账单");
                        oppd.put("OPERA_TIME", new DateUtil().getTime());
                        oppd.put("OPERATOR", user.getNAME());
                        recordService.save(oppd);
                    }
                }
                //获取 所有存在的账单
                // billlists.get("CODE");
                //if(jsonObject2.get("data1").equals(billlists.get("CODE"))){
                StringBuilder sb = new StringBuilder();
                String sbString = "";
                try {
                    Iterator iterator = jsonObject2.keys();
                    while (iterator.hasNext()) {
                        String key2 = (String) iterator.next();
                        //CollectionUtils.isEmpty((Collection) jsonObject2.get(key2));
                        //获取已经填写的 账单类型
                        if (StringHelper.isNotEmpty(jsonObject2.get(key2).toString())) {
                            for (PageData billlists : billlist) {
                                if ((key2.toString()).contains(billlists.get("CODE").toString())) {
                                    //System.out.println(billlists.get("CODE"));
                                    part++;
                                    String zaid = this.get32UUID();
                                    billroom.put("ID", zaid);
                                    billroom.put("CREATE_ID", user.getUSER_ID());
                                    billroom.put("CREATE_DATE", DateUtil.getTime());
                                    billroom.put("UPDATE_DATE", DateUtil.getTime());
                                    billroom.put("UPDATE_ID", user.getUSER_ID());
                                    billroom.put("SORT", "0");
                                    billroom.put("IS_DEL", "0");
                                    billroom.put("BILL_SIGNER", jsonObject2.getString("data1[BILL_SIGNER]").toString());
                                    billroom.put("START_DATE", jsonObject2.getString("data1[START_DATE]"));
                                    billroom.put("END_DATE", jsonObject2.getString("data1[END_DATE]"));
                                    billroom.put("PAY_DATE", jsonObject2.getString("data1[PAY_DATE]"));
                                    billroom.put("ROOM_ID", stu.get("ROOM_ID").toString());
                                    billroom.put("BILL_TYPE", 2);//增加其他类型账单
                                    billroom.put("BILL_NAME", billlists.get("CODE"));
                                    billroom.put("TOTAL_PRICE", jsonObject2.getString("" + key2 + ""));
                                    billroom.put("INFO", jsonObject2.getString("data1[INFO]"));
                                    billroom.put("ALLOT_BILL", jsonObject2.getString("data1[ALLOT_BILL" + part + "]"));
                                    if ("停车费".equals(billlists.get("CODE").toString())) {
                                        if ("2".equals(jsonObject2.getString("data1[MKXF]"))) {//买卡
                                            billroom.put("STATE", "eda58d7280554dd9918207d27e2d4654");//已收款
                                            billroom.put("CHECK_STATE", "01");//手动添加账单 暂时归到 待审核中
                                            billroom.put("PARK_CARD", jsonObject2.getString("data1[PARK_CARD" + part + "]"));
                                            billroom.put("PRICE_TYPE", "0");//不是收入支出了  是 买卡 和消费
                                            billroom.put("ROOM_ID", jsonObject2.getString("data1[ROOMID" + part + "]"));//停车场多选房间
                                            billroom.put("ALLOT_BILL", jsonObject2.getString("data1[ALLOT_BILL" + part + "]"));
                                        } else {
                                            if ("1".equals(jsonObject2.getString("data1[PRICE_TYPE1]"))) {// 1卡  收入2
                                                billroom.put("TOTAL_PRICE", "");//消费的时候 不存price
                                                billroom.put("STATE", "eda58d7280554dd9918207d27e2d4654");//已收款
                                                billroom.put("PRICE_TYPE", "0");//不是收入支出了  是 买卡 和消费
                                                billroom.put("PARK_CARD", jsonObject2.getString("data1[PARK_CARD" + part + "]"));
                                                billroom.put("ALLOT_BILL", jsonObject2.getString("data1[ALLOT_BILL" + part + "]"));
                                                if (jsonObject2.containsKey("data1[PART_START" + part + "]")) {
                                                    billroom.put("PART_START", jsonObject2.getString("data1[PART_START" + part + "]"));
                                                }
                                                if (jsonObject2.containsKey("data1[PART_END" + part + "]")) {
                                                    billroom.put("PART_END", jsonObject2.getString("data1[PART_END" + part + "]"));
                                                }
                                            } else {//收入的时候 存现金账户
                                                billroom.put("TOTAL_PRICE", jsonObject2.getString("data1[TOTAL_PRICE]"));
                                                billroom.put("STATE", "eda58d7280554dd9918207d27e2d4654");//已收款
                                                billroom.put("PRICE_TYPE", "0");//不是收入支出了  是 买卡 和消费
                                                if (jsonObject2.containsKey("data1[PART_START" + part + "]")) {
                                                    billroom.put("PART_START", jsonObject2.getString("data1[PART_START" + part + "]"));
                                                }
                                                if (jsonObject2.containsKey("data1[PART_END" + part + "]")) {
                                                    billroom.put("PART_END", jsonObject2.getString("data1[PART_END" + part + "]"));
                                                }
                                            }
                                        }
                                    } else {
                                        billroom.put("STATE", "682177ade393478e8224f9a3aa385a6c");//未收款
                                        billroom.put("CHECK_STATE", "01");//手动添加账单 暂时归到 待审核中
                                        billroom.put("PRICE_TYPE", jsonObject2.getString("data1[PRICE_TYPE" + part + "]"));//收入 支出
                                    }
                                    if (jsonObject2.containsKey("data1[ALLOT_BILL" + part + "")) {
                                        billroom.put("ALLOT_BILL", jsonObject2.getString("data1[ALLOT_BILL" + part + "]"));//公户 私户
                                    }
                                    billroom.put("MAKE_BILL_TYPE", "1");//手动添加
                                    billService.save(billroom);
                                    //billroom.put("PRICE_TYPE",jsonObject2.getString("data1[" + billlists.get("CODE")+"+PRICE_TYPE]"));//支出  收入
                                    //同时添加 多个杂费 的处理方法
                                          /*  for(int i=1;i<pd.size();i++){
                                                if(jsonObject2.containsKey("data1[押金" +i+"]")){
                                                    String zuid=this.get32UUID();
                                                    billroom.put("ID",zuid);
                                                    billroom.put("CREATE_ID",user.getUSER_ID());
                                                    billroom.put("CREATE_DATE",DateUtil.getTime());
                                                    billroom.put("SORT","0");
                                                    billroom.put("IS_DEL","0");
                                                    billroom.put("BILL_SIGNER",jsonObject2.getString("data1[BILL_SIGNER]").toString());
                                                    billroom.put("START_DATE",jsonObject2.getString("data1[START_DATE]"));
                                                    billroom.put("END_DATE",jsonObject2.getString("data1[END_DATE]"));
                                                    billroom.put("PAY_DATE",jsonObject2.getString("data1[PAY_DATE]"));
                                                    billroom.put("ROOM_ID",stu.get("ROOM_ID").toString());
                                                    billroom.put("BILL_NAME",jsonObject2.getString("data1[yajin]"));
                                                    billroom.put("TOTAL_PRICE",jsonObject2.getString("data1[押金" +i+"]"));
                                                    billroom.put("INFO",jsonObject2.getString("data1[INFO]"));
                                                    billroom.put("STATE","682177ade393478e8224f9a3aa385a6c");
                                                    billroom.put("CHECK_STATE","0");//手动添加账单 暂时归到 待审核中
                                                    billroom.put("MAKE_BILL_TYPE","1");//手动添加
                                                    billroom.put("PRICE_TYPE",jsonObject2.getString("data1[PRICE_TYPE" +i+"]"));//支出  收入
                                                    billroom.put("ALLOT_BILL",jsonObject2.getString("data1[ALLOT_BILL" +i+"]"));//公户 私户
                                                    billService.save(billroom);
                                                }
                                            }*/

                                    //杂费附件
                                    if (jsonObject2.containsKey("data1[ATTACHMENT][0][name]")) {
                                        PageData pds = new PageData();
                                        pds.put("ID", this.get32UUID());    //主键
                                        pds.put("OID", zaid);
                                        pds.put("NAME", pd.get("data1[ATTACHMENT][0][name]"));
                                        pds.put("EXT", pd.get("data1[ATTACHMENT][0][ext]"));
                                        pds.put("PATH", pd.get("data1[ATTACHMENT][0][url]"));
                                        pds.put("TYPE", "bill");
                                        pds.put("SORT", "1");
                                        pds.put("REMARK", "");
                                        pds.put("CREATE_TIME", new DateUtil().getTime());
                                        pds.put("CREATE_ID", user.getUSER_ID());
                                        pds.put("IS_DELETED", 0);
                                        attachmentService.saveAttachment(pds);
                                    }

                                    //保存操作记录
                                    PageData oppd = new PageData();
                                    oppd.put("ID", this.get32UUID());    //主键
                                    oppd.put("IS_DEL", 0); //是否删除
                                    oppd.put("SORT", 0); //排序
                                    oppd.put("BILL_ID", zaid); //排序
                                    oppd.put("CREATE_ID", user.getUSER_ID()); //创建用户
                                    oppd.put("CREATE_DATE", new DateUtil().getTime()); //创建时间
                                    oppd.put("ALLOT_BILL",jsonObject2.getString("data1[ALLOT_BILL" + part + "]")); //收款账户
                                    //oppd.put("DETAILS","新增一个"+pd.get("BILL_NAME").toString()+"账单,金额"+pd.get("TOTAL_PRICE").toString());
                                    oppd.put("DETAILS", "新增一个账单");
                                    oppd.put("OPERA_TIME", new DateUtil().getTime());
                                    oppd.put("OPERATOR", user.getNAME());
                                    recordService.save(oppd);
                                }
                            }
                        }

                        //sb.append("="+jsonObject.getString(key));
                    }
                } catch (JSONException e) {
                    e.printStackTrace();
                }

            }


            PageData pds = new PageData();
            //JSONObject jo = (JSONObject) ATTACHMENT.get(i);
            pds.put("ID", this.get32UUID());    //主键
            pds.put("OID", BID);
            pds.put("NAME", pd.get("data1[ATTACHMENT][0][name]"));
            pds.put("EXT", pd.get("data1[ATTACHMENT][0][ext]"));
            pds.put("PATH", pd.get("data1[ATTACHMENT][0][url]"));
            pds.put("TYPE", "bill");
            pds.put("SORT", "1");
            pds.put("REMARK", "");
            pds.put("CREATE_TIME", new DateUtil().getTime());
            pds.put("CREATE_ID", user.getUSER_ID());
            pds.put("IS_DELETED", 0);
            //attachmentService.saveAttachment(pds);
           /* System.out.println(pd.toString());
            pd.get("data1[ATTACHMENT][0][name]");
            System.out.println( pd.get("data1[ATTACHMENT][0][name]"));
            //Map map12 = JSONHelper.json2Map(pd.toString());
            JSONObject jsonObject1=JSONObject.fromObject(pd);
            JSONArray ATTACHMENT = jsonObject1.getJSONArray("data1[ATTACHMENT][0][name]");
            //保存附件信息
            if (ATTACHMENT.size() > 0) {
                for (int i = 0; i < ATTACHMENT.size(); i++) {
                    PageData pds = new PageData();
                    JSONObject jo = (JSONObject) ATTACHMENT.get(i);
                    pds.put("ID", this.get32UUID());    //主键
                    pds.put("OID", "账单id");
                    pds.put("NAME", jo.get("name"));
                    pds.put("EXT", jo.get("ext"));
                    pds.put("PATH", jo.get("url"));
                    pds.put("TYPE", "contract");
                    pds.put("SORT", i + 1);
                    pds.put("REMARK", "");
                    pds.put("CREATE_TIME", new DateUtil().getTime());
                    pds.put("CREATE_ID", user.getUSER_ID());
                    pds.put("IS_DELETED", 0);
                    attachmentService.saveAttachment(pd);
                }
            }*/


            res.put("data", "");
            res.put("errcode", "0");
            res.put("errmsg", "ok");
            transactionManager.commit(status);
        } catch (Exception e) {
            transactionManager.rollback(status);
            logger.error(e.toString(), e);
            res.put("data", "");
            res.put("errcode", "1");
            res.put("errmsg", e.toString());
        }
        return res;
    }

    /**
     * 修改账单
     */
    @RequestMapping(value = "/billedit")
    @ResponseBody
    public PageData billedit() {
        DefaultTransactionDefinition defaultTransactionDefinition = new DefaultTransactionDefinition();
        defaultTransactionDefinition.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRED);
        TransactionStatus status = transactionManager.getTransaction(defaultTransactionDefinition);

        logBefore(logger, "修改账单");
        PageData res = new PageData();
        PageData pd = this.getPageData();
        //获取当前登录用户
        Subject currentUser = SecurityUtils.getSubject();
        Session session = currentUser.getSession();
        User user = (User) session.getAttribute(Const.SESSION_USER);
        try {

            pd.put("CREATE_ID", user.getUSER_ID()); //创建时间
            pd.put("CREATE_DATE", new DateUtil().getTime()); //创建时间
            pd.put("UPDATE_ID", user.getUSER_ID()); //修改人id
            pd.put("UPDATE_DATE", new DateUtil().getTime()); //修改时间
            pd.put("SORT", 0); //排序
            pd.put("IS_DEL", 0); //是否删除
            pd.put("IS_READ", 1); //是否已读
            pd.put("CHECK_STATE", "01"); //账单审核状态

            List<PageData> listBill = billService.listBill(pd);//查找账单信息
            billService.billedit(pd);
            //修改账单的附件之前 需要把之前的附件 清空
            attachmentService.deleteAttachmentByOid(pd);
            //增加账单 附件
            for (int i = 0; i < pd.size() - 14; i++) {
                System.out.println("ATTACHMENT[" + i + "][name]");
                if (pd.containsKey("ATTACHMENT[" + i + "][name]")) {
                    PageData pds = new PageData();
                    pds.put("ID", this.get32UUID());    //主键
                    pds.put("OID", pd.get("ID"));
                    pds.put("NAME", pd.get("ATTACHMENT[" + i + "][name]"));
                    pds.put("EXT", pd.get("ATTACHMENT[" + i + "][ext]"));
                    pds.put("PATH", pd.get("ATTACHMENT[" + i + "][url]"));
                    pds.put("SIZE", pd.get("ATTACHMENT[" + i + "][size]"));
                    pds.put("TYPE", "bill");
                    pds.put("SORT", "1");
                    pds.put("REMARK", "");
                    pds.put("CREATE_TIME", new DateUtil().getTime());
                    pds.put("CREATE_ID", user.getUSER_ID());
                    pds.put("IS_DELETED", 0);
                    attachmentService.saveAttachment(pds);
                }

            }


            //保存操作记录
            PageData oppd = new PageData();
            oppd.put("ID", this.get32UUID());    //主键
            oppd.put("IS_DEL", 0); //是否删除
            oppd.put("SORT", 0); //排序
            oppd.put("CREATE_ID", user.getUSER_ID()); //创建用户
            oppd.put("CREATE_DATE", new DateUtil().getTime()); //创建时间
            oppd.put("DETAILS", "修改账单金额:" + listBill.get(0).get("TOTAL_PRICE").toString() + "-->" + pd.get("TOTAL_PRICE").toString());
            oppd.put("BILL_ID", pd.get("ID"));//保存 账单id
            String ALLOT_BILL = "";
            if (pd.containsKey("ALLOT_BILL")) {
                //转换公户 私户 数据问题
                if ("0".equals(pd.get("ALLOT_BILL").toString())) {
                    ALLOT_BILL = "公户";
                } else {
                    ALLOT_BILL = "私户";
                }
            }
            oppd.put("ALLOT_BILL", "修改收款账户:" + listBill.get(0).get("ALLOT_BILL").toString() + "-->" + ALLOT_BILL);//保存 收款账户类型
            oppd.put("OPERA_TIME", new DateUtil().getTime());
            oppd.put("OPERATOR", user.getNAME());
            recordService.save(oppd);

            //--------------------个推消息---------------------
            //个推消息
            PageData CID = new PageData();
            String title = "你有一条待审批的账单";
            String text = "请前去审批";
            List<PageData> listcid = contractService.findlistCID(CID);
            List<String> cid = PushToApp.userCID("SPQX_ZDSP", listcid);//获取由此权限的用户cid(帐单审批权限)
            if (cid.size() > 0) {
                JSONObject json = new JSONObject();
                json.put("ID", pd.get("ID"));
                json.put("TYPE", 1);
                json.put("TITLE", "你有一条待审批的账单");
                json.put("TEXT", "请前去审批");
                String ID = json.toString();
                PushToApp.PushPrivate(title, text, cid, ID);
            }

//-----------------------------------------------------------------------
            res.put("data", "");
            res.put("errcode", "0");
            res.put("errmsg", "ok");
            transactionManager.commit(status);
        } catch (Exception e) {
            transactionManager.rollback(status);
            logger.error(e.toString(), e);
            res.put("data", "");
            res.put("errcode", "1");
            res.put("errmsg", e.toString());
        }
        return res;
    }

    /**
     * 审批事项 审核账单
     */
    @RequestMapping(value = "/shenhebill")
    @ResponseBody
    public PageData shenhebill() {
        logBefore(logger, "新增账单");
        PageData res = new PageData();
        PageData pd = this.getPageData();
        //获取当前登录用户
        Subject currentUser = SecurityUtils.getSubject();
        Session session = currentUser.getSession();
        User user = (User) session.getAttribute(Const.SESSION_USER);
        try {

            pd.put("CREATE_ID", user.getUSER_ID()); //创建时间
            pd.put("CREATE_DATE", new DateUtil().getTime()); //创建时间
            pd.put("SORT", 0); //排序
            pd.put("IS_DEL", 0); //是否删除
            //保存操作记录
            PageData oppd = new PageData();
            List<PageData> listBill = billService.listBill(pd);//查找账单信息
            //通过
            if ("1".equals(pd.get("CHECK_STATE"))) {
                //最高审核通过后 才把账单状态改成 1
                int i=Integer.parseInt(listBill.get(0).get("CHECK_STATE").toString())+1;
                pd.put("USER_ID", user.getUSER_ID());
                PageData data = roleService.shenHeAuth(pd);
                if(data.containsKey("BILL_AUTH")){
                    if(1==Integer.parseInt(data.get("BILL_AUTH").toString())){//开启一级审核
                        PageData billdata = new PageData();
                        billdata.put("TOTAL_PRICE", listBill.get(0).get("TOTAL_PRICE_TEMP"));
                        billdata.put("ID",pd.get("ID"));
                        billdata.put("CHECK_STATE","1");
                        billService.shenhebill(billdata);

                        PageData cb = new PageData();
                        cb.put("ID",UuidUtil.get32UUID());
                        cb.put("CREATE_ID",user.getUSER_ID());
                        cb.put("CREATE_DATE",DateUtil.getTimes());
                        cb.put("IS_DEL","0");
                        cb.put("CB_ID",pd.get("id"));
                        cb.put("STATE","1");//1 通过   2 未通过
                        cb.put("REMARK","");//备注
                        contractService.savetbcheck(cb);//保存业务记录
                    }
                    if(2==Integer.parseInt(data.get("BILL_AUTH").toString())){//开启2级审核
                        if(3==i){
                            PageData billdata = new PageData();
                            billdata.put("TOTAL_PRICE", listBill.get(0).get("TOTAL_PRICE_TEMP"));
                            billdata.put("ID",pd.get("ID"));
                            billdata.put("CHECK_STATE","1");
                            billService.shenhebill(billdata);
                        }else {
                            String stateStr="0"+i;
                            pd.put("CHECK_STATE",stateStr);
                        }
                        billService.shenhebill(pd);
                        PageData cb = new PageData();
                        cb.put("ID",UuidUtil.get32UUID());
                        cb.put("CREATE_ID",user.getUSER_ID());
                        cb.put("CREATE_DATE",DateUtil.getTime());
                        cb.put("IS_DEL","0");
                        cb.put("CB_ID",pd.get("id"));
                        cb.put("STATE","1");//1 通过   2 未通过
                        cb.put("REMARK","");//备注
                        contractService.savetbcheck(cb);//保存业务记录
                    }
                    if(3==Integer.parseInt(data.get("BILL_AUTH").toString())){//开启3级审核
                        if(4==i){
                            PageData billdata = new PageData();
                            billdata.put("TOTAL_PRICE", listBill.get(0).get("TOTAL_PRICE_TEMP"));
                            billdata.put("ID",pd.get("ID"));
                            billdata.put("CHECK_STATE","1");
                            billService.shenhebill(billdata);
                        } else {
                            String stateStr="0"+i;
                            pd.put("CHECK_STATE",stateStr);
                        }
                        billService.shenhebill(pd);
                        PageData cb = new PageData();
                        cb.put("ID",UuidUtil.get32UUID());
                        cb.put("CREATE_ID",user.getUSER_ID());
                        cb.put("CREATE_DATE",DateUtil.getTime());
                        cb.put("IS_DEL","0");
                        cb.put("CB_ID",pd.get("id"));
                        cb.put("STATE","1");//1 通过   2 未通过
                        cb.put("REMARK","");//备注
                        contractService.savetbcheck(cb);//保存业务记录
                    }
                    if(4==Integer.parseInt(data.get("BILL_AUTH").toString())){//开启4级审核
                        if(5==i){
                            PageData billdata = new PageData();
                            billdata.put("TOTAL_PRICE", listBill.get(0).get("TOTAL_PRICE_TEMP"));
                            billdata.put("ID",pd.get("ID"));
                            billdata.put("CHECK_STATE","1");
                            billService.shenhebill(billdata);

                            PageData cb = new PageData();
                            cb.put("ID",UuidUtil.get32UUID());
                            cb.put("CREATE_ID",user.getUSER_ID());
                            cb.put("CREATE_DATE",DateUtil.getTimes());
                            cb.put("IS_DEL","0");
                            cb.put("CB_ID",pd.get("id"));
                            cb.put("STATE","1");//1 通过   2 未通过
                            cb.put("REMARK","");//备注
                            contractService.savetbcheck(cb);//保存业务记录
                        }else {
                            String stateStr="0"+i;
                            pd.put("CHECK_STATE",stateStr);
                            billService.shenhebill(pd);
                            PageData cb = new PageData();
                            cb.put("ID",UuidUtil.get32UUID());
                            cb.put("CREATE_ID",user.getUSER_ID());
                            cb.put("CREATE_DATE",DateUtil.getTime());
                            cb.put("IS_DEL","0");
                            cb.put("CB_ID",pd.get("id"));
                            cb.put("STATE","1");//1 通过   2 未通过
                            cb.put("REMARK","");//备注
                            contractService.savetbcheck(cb);//保存业务记录
                        }
                    }
                }
                if (pd.containsKey("DETAILS")) {
                    oppd.put("DETAILS", "审核账单通过:" + pd.get("DETAILS").toString());
                }
            } else if ("2".equals(pd.get("CHECK_STATE"))) {
                pd.put("CHECK_STATE", "2");
                pd.put("TOTAL_PRICE", listBill.get(0).get("TOTAL_PRICE"));//恢复原来的账单金额
                if (pd.containsKey("DETAILS")) {
                    oppd.put("DETAILS", "审核账单驳回:" + pd.get("DETAILS").toString());
                }
                billService.shenhebill(pd);
            }
            oppd.put("ID", this.get32UUID());    //主键
            oppd.put("IS_DEL", 0); //是否删除
            oppd.put("SORT", 0); //排序
            oppd.put("CREATE_ID", user.getUSER_ID()); //创建用户
            oppd.put("CREATE_DATE", new DateUtil().getTime()); //创建时间
            oppd.put("OPERA_TIME", new DateUtil().getTime());
            oppd.put("OPERATOR", user.getNAME());
            oppd.put("BILL_ID", pd.get("ID"));//保存 账单id
            recordService.save(oppd);
            res.put("data", "");
            res.put("errcode", "0");
            res.put("errmsg", "ok");
        } catch (Exception e) {
            logger.error(e.toString(), e);
            res.put("data", "");
            res.put("errcode", "1");
            res.put("errmsg", e.toString());
        }
        return res;
    }

    /**
     * 新增付款 收费
     */
    @RequestMapping(value = "/savebillpay")
    @ResponseBody
    public PageData savebillpay() {
        DefaultTransactionDefinition defaultTransactionDefinition = new DefaultTransactionDefinition();
        defaultTransactionDefinition.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRED);
        TransactionStatus status = transactionManager.getTransaction(defaultTransactionDefinition);
        logBefore(logger, "新增账单");
        PageData res = new PageData();
        PageData pd = this.getPageData();
        //获取当前登录用户
        Subject currentUser = SecurityUtils.getSubject();
        Session session = currentUser.getSession();
        User user = (User) session.getAttribute(Const.SESSION_USER);
        try {
            pd.put("ID", this.get32UUID());    //主键
            pd.put("CREATE_ID", user.getUSER_ID()); //创建时间
            pd.put("UPDATE_ID", user.getUSER_ID()); //创建用户
            pd.put("CREATE_DATE", new DateUtil().getTime()); //创建时间
            pd.put("UPDATE_DATE", new DateUtil().getTime()); //更新时间
            pd.put("ACT_PAY_DATE", pd.get("ACT_PAY_DATE")); //实际付款时间
            pd.put("SORT", 0); //排序
            pd.put("IS_DEL", 0); //是否删除
            pd.put("IS_READ", 1);
            //如果存在滞纳金 增加一条滞纳金流水
            if (pd.containsKey("PAY_PRICEznj")) {
                PageData znj = new PageData();
                znj.put("ID", this.get32UUID());    //主键
                znj.put("CREATE_ID", user.getUSER_ID()); //创建时间
                znj.put("CREATE_DATE", new DateUtil().getTime()); //创建时间
                znj.put("SORT", 0); //排序
                znj.put("IS_DEL", 0); //是否删除
                znj.put("BILL_ID", pd.get("BILL_ID").toString());
                znj.put("PAY_METHOD", pd.get("PAY_METHODznj"));
                znj.put("COLLECTION_TYPE", pd.get("ALLOT_BILLznj"));
                znj.put("PAY_PRICE", pd.get("PAY_PRICEznj"));
                znj.put("PAY_TRANSACTION", pd.get("PAY_TRANSACTIONznj"));
                znj.put("IS_RECEIPT", pd.get("IS_RECEIPTznj"));
                znj.put("INFO", pd.get("INFOznj"));
                //billService.savebillpay(znj); //确认付款
            }
            //增加账单 附件
            for (int i = 0; i < pd.size() - 19; i++) {
                //System.out.println("ATTACHMENT["+i+"][name]");
                if (pd.containsKey("ATTACHMENT[" + i + "][name]")) {
                    PageData pds = new PageData();
                    pds.put("ID", this.get32UUID());    //主键
                    pds.put("OID", pd.get("BILL_ID"));
                    pds.put("NAME", pd.get("ATTACHMENT[" + i + "][name]"));
                    pds.put("EXT", pd.get("ATTACHMENT[" + i + "][ext]"));
                    pds.put("PATH", pd.get("ATTACHMENT[" + i + "][url]"));
                    pds.put("TYPE", "bill");
                    pds.put("SORT", "1");
                    pds.put("REMARK", "");
                    pds.put("CREATE_TIME", new DateUtil().getTime());
                    pds.put("CREATE_ID", user.getUSER_ID());
                    pds.put("IS_DELETED", 0);
                    attachmentService.saveAttachment(pds);
                }

            }
            //如果所有账单已经结清 就把合同 状态修改为 已完结
            PageData pdbill = new PageData();
            pdbill.put("ID", pd.get("BILL_ID"));
            List<PageData> list = billService.listBill(pdbill);
            if (list.size() > 0) {
                if ("退租".equals(list.get(0).get("BILL_NAME"))) {
                    //如果当前的账单 为 退租账单 就把 合同 状态 修改为 已完结
                    PageData pds = new PageData();
                    pds.put("id", list.get(0).get("CONTRACT_ID"));
                    billService.UPCON(pds);
                }
                //支出账单  标识
//                pd.put("PRICE_TYPE", list.get(0).get("PRICE_TYPE"));
                //fixme 假如是押金之类的数据 就把 存流水明细表 PRICE_TYPE=1  统计数据的时候需要注意 统计账单表的类型
                if("1".equals(list.get(0).get("BILL_TYPE"))&&"eda58d7280554dd9918207d27e2d4654".equals(list.get(0).get("STATE"))){
                    pd.put("PRICE_TYPE", "1");
                }else {
                    pd.put("PRICE_TYPE", list.get(0).get("PRICE_TYPE"));
                }
                //保存账单前 付款后 修改账单状态  未支付>已支付  存在滞纳金 就把滞纳金存到账单中
                billService.editbillpay(pd);
            }
            if (pd.containsKey("PAY_PRICEznj")) {//计算存在滞纳金的问题
                float PAY_PRICE = Float.parseFloat(pd.get("PAY_PRICEznj").toString()) + Float.parseFloat(pd.getString("PAY_PRICE").toString());
                pd.put("PAY_PRICE", PAY_PRICE);
            }
            //收款的时候 如果账单是 负数  应该是支出类型
            float PAY_PRICE = Float.parseFloat(pd.get("PAY_PRICE").toString());
            if (PAY_PRICE < 0) {
                pd.put("PRICE_TYPE", "1");
                PAY_PRICE = PAY_PRICE * -1;
                pd.put("PAY_PRICE", PAY_PRICE);
            }
            pd.put("ID",this.get32UUID());
            billService.savebillpay(pd); //确认付款  存流水明细表


            //保存操作记录
            PageData oppd = new PageData();
            oppd.put("ID", this.get32UUID());    //主键
            oppd.put("IS_DEL", 0); //是否删除
            oppd.put("SORT", 0); //排序
            oppd.put("CREATE_ID", user.getUSER_ID()); //创建用户
            oppd.put("CREATE_DATE", new DateUtil().getTime()); //创建时间
            oppd.put("OPERA_TIME", new DateUtil().getTime());
            oppd.put("OPERATOR", user.getNAME());
            oppd.put("DETAILS", "确认收费");
            oppd.put("BILL_ID", pd.get("BILL_ID"));//保存 账单id
            recordService.save(oppd);

            //--------------------个推消息---------------------
            //个推消息
            PageData CID = new PageData();
            String title = "您有一条收费信息";
            String text = "前往去查看";
            List<PageData> listcid = contractService.findlistCID(CID);
            List<String> cid = PushToApp.userCID("SPQX_ZDSP", listcid);//获取由此权限的用户cid(帐单审批权限)
            if (cid.size() > 0) {
                JSONObject json = new JSONObject();
                json.put("ID", pd.get("ID"));
                json.put("TYPE", 1);//1为账单，0为合同
                json.put("TITLE", "你有一条待审批的账单");
                json.put("TEXT", "请前去审批");
                String ID = json.toString();
                PushToApp.PushPrivate(title, text, cid, ID);
            }

//----------------------------------------------------------------------
            res.put("data", "");
            res.put("errcode", "0");
            res.put("errmsg", "ok");
            transactionManager.commit(status);
        } catch (Exception e) {
            transactionManager.rollback(status);
            logger.error(e.toString(), e);
            res.put("data", "");
            res.put("errcode", "1");
            res.put("errmsg", e.toString());
        }
        return res;
    }

    /**
     * 新增付款 批量收费
     */
    @RequestMapping(value = "/savebillpayALL")
    @ResponseBody
    public PageData savebillpayALL() {
        logBefore(logger, "新增账单");
        PageData res = new PageData();
        PageData pd = this.getPageData();
        //获取当前登录用户
        Subject currentUser = SecurityUtils.getSubject();
        Session session = currentUser.getSession();
        User user = (User) session.getAttribute(Const.SESSION_USER);
        try {
            //pd.put("ID", this.get32UUID());    //主键
            pd.put("CREATE_ID", user.getUSER_ID()); //创建时间
            pd.put("CREATE_DATE", new DateUtil().getTime()); //创建时间
            pd.put("SORT", 0); //排序
            pd.put("IS_DEL", 0); //是否删除
            String str = pd.get("BILL_ID").toString();
            List<String> resultbill = Arrays.asList(str.split(","));
            //保存账单前 付款后 批量 修改账单状态  未支付>已支付
            billService.editbillpayALL(resultbill);
            List<PageData> newList = new ArrayList<PageData>();
            for (int i = 0; i < resultbill.size(); i++) {
                pd.put("ID", resultbill.get(i));
                List<PageData> list = billService.listBill(pd);
                PageData pagebill = new PageData();
                pagebill.put("ID", this.get32UUID());
                pagebill.put("BILL_ID", list.get(0).get("ID"));
                pagebill.put("PAY_PRICE", list.get(0).get("TOTAL_PRICE"));
                pagebill.put("CREATE_ID", user.getUSER_ID());
                pagebill.put("CREATE_DATE", DateUtil.getTime());
                pagebill.put("SORT", "0");
                pagebill.put("IS_DEL", "0");
                pagebill.put("PAY_METHOD", "");
                pagebill.put("COLLECTION_TYPE", "公户");
                pagebill.put("PAY_TRANSACTION", "");
                pagebill.put("IS_RECEIPT", "有");
                pagebill.put("INFO", "备注");
                newList.add(pagebill);
            }
            billService.savebillpayALL(newList); //批量 确认付款
            res.put("data", "");
            res.put("errcode", "0");
            res.put("errmsg", "ok");
        } catch (Exception e) {
            logger.error(e.toString(), e);
            res.put("data", "");
            res.put("errcode", "1");
            res.put("errmsg", e.toString());
        }
        return res;
    }

    /**
     * 根据账单id 查找 账单信息
     */
    @RequestMapping(value = "/listBill")
    @ResponseBody
    public PageData listArr() {
        logBefore(logger, "Building列表");
        PageData res = new PageData();
        PageData pd = this.getPageData();
        try {
            List<PageData> list = billService.listBill(pd);
            if (list.size() > 0) {
                res.put("data", list.get(0));
                pd.put("id", list.get(0).get("ID"));
                List<PageData> attachmentData = attachmentService.findByOId(pd);//查看附件
                res.put("attachmentData", attachmentData);
            }
            res.put("errcode", "0");
            res.put("errmsg", "ok");
        } catch (Exception e) {
            logger.error(e.toString(), e);
            res.put("data", "");
            res.put("errcode", "1");
            res.put("errmsg", e.toString());
        }
        return res;
    }

    /**
     * 审核账单
     *
     * @return
     */
    @RequestMapping(value = "/checkbill")
    @ResponseBody
    public Object checkContract() {
        logBefore(logger, "审核账单");
        PageData pd = new PageData();
        PageData resultPd = new PageData();
        try {
            pd = this.getPageData();
            if (null == pd.get("checkState")) {
                resultPd.put("errcode", "1");
                resultPd.put("errmsg", "请完整填写checkState参数");
            } else {
                billService.check(pd);
                resultPd.put("errcode", "0");
                resultPd.put("errmsg", "审核成功");
            }
        } catch (Exception e) {
            resultPd.put("errcode", "1");
            resultPd.put("errmsg", "审核失败");
            logger.error(e.toString(), e);
        }
        return resultPd;
    }

    /* ===============================app账单接口================================== */

    /**
     * 根据合同id 查找 账单信息
     */
    @RequestMapping(value = "/billdetail")
    @ResponseBody
    public PageData billdetail(HttpServletRequest request) {
        logBefore(logger, "");
        PageData res = new PageData();
        PageData pd = this.getPageData();
        //获取当前登录用户
        Subject currentUser = SecurityUtils.getSubject();
        Session session = currentUser.getSession();
        User user = (User) session.getAttribute(Const.SESSION_USER);
        try {
            pd.put("USER_ID",user.getUSER_ID());
            List<PageData> list = billService.billdetail(pd);//获取账单基本信息
            List<PageData> list1 = billService.billdetaillist(pd);//租金
            PageData list2 = billService.billdetaillistsum(pd);//总金额
            PageData late_price = billService.billdetaillistLate(pd);//滞纳金
            PageData ress = new PageData();
            //获取域名地址 用于组装图片全路径
            StringBuffer url = request.getRequestURL();
            String tempContextUrl = url.delete(url.length() - request.getRequestURI().length(), url.length()).append("/").toString();
            List<String> listdata = new ArrayList<>();
            PageData att = new PageData();
            att.put("id", pd.get("ID"));
            List<PageData> attachmentData = attachmentService.findByOId(att);//查看附件
            if (attachmentData.size() > 0) {
                for (int k = 0; k < attachmentData.size(); k++) {
                    listdata.add(tempContextUrl + attachmentData.get(k).get("PATH"));//存放账单详情img 数组
                }
                ress.put("PATHLIST", listdata);
            }
            ress.put("PATHLIST", listdata);
            if (null == list2) {
                ress.put("ALLPRICE", "");
            } else {
                ress.put("ALLPRICE", list2.get("ALLPRICE"));
            }
            if (list.size() > 0) {
                ress.put("SIGNER", list.get(0).get("SIGNER"));
                ress.put("ROOM_NUM", list.get(0).get("ROOM_NUM"));
                ress.put("START_DATE", list.get(0).get("START_DATE"));
                ress.put("END_DATE", list.get(0).get("END_DATE"));
                ress.put("AREA", list.get(0).get("AREA"));
                ress.put("TEL", list.get(0).get("TEL"));
                ress.put("INFO", list.get(0).get("INFO"));
                ress.put("STATE", list.get(0).get("STATE"));
                ress.put("PAY_DATE", list.get(0).get("PAY_DATE"));
                ress.put("REA_DATA", list.get(0).get("REA_DATA"));//实际付款时间
                if (late_price.containsKey("PRICE")&&late_price.getString("PRICE").indexOf("-")==-1) {//存在滞纳金
                    list1.add(late_price);
                    ress.put("LIST", list1);//存放账单的 租金  和 滞纳金
                } else {
                    ress.put("LIST", list1);//存放账单的 租金
                }
                //新增账单的操作权限OPERA_AUTH
                if (null != pd.get("userid")) {
                    pd.put("USER_ID", pd.get("userid"));
                    PageData dataAuth = roleService.authListByLoginUser(pd);
                    if(dataAuth!=null){
                        if (dataAuth.get("AUTH_CODE").toString().indexOf("SPQX_ZDSP") != -1) {
                            ress.put("OPERA_AUTH", 1);
                        } else {
                            ress.put("OPERA_AUTH", 0);
                        }
                    }else {
                        ress.put("OPERA_AUTH", 1);
                    }

                }
                res.put("data", ress);
            } else {
                res.put("data", "");
            }
            res.put("errcode", "0");
            res.put("errmsg", "ok");
        } catch (Exception e) {
            logger.error(e.toString(), e);
            res.put("data", "");
            res.put("errcode", "1");
            res.put("errmsg", e.toString());
        }
        return res;
    }

    /**
     * 租客账单详情(分页)
     */
    @RequestMapping(value = "/billlist", produces = "text/html;charset=UTF-8")
    @ResponseBody
    public Object billlist(Page page) {
        PageData pd = new PageData();
        PageData pds = new PageData();
        Map<String, Object> map = new HashMap<String, Object>();
        List<PageData> varList;
        String datalayui = null;
        //获取当前登录用户
        Subject currentUser = SecurityUtils.getSubject();
        Session session = currentUser.getSession();
        User user = (User) session.getAttribute(Const.SESSION_USER);
        try {
            pd = this.getPageData();
            pds.put("page", pd.get("page"));
            pds.put("limit", pd.get("row"));
            pds.put("USER_ID",user.getUSER_ID());
            if (null != pd.get("state_id")) {
                pds.put("state_id", pd.get("state_id"));
                if("54785222cao5568844255545587533c6".equals(pd.get("state_id").toString())){//将到期的逻辑处理
                    pds.put("state_id", null);
                    pds.put("date_flag",DateUtil.getAfterDayDate("90"));
                }
                if("7092004518204020890a2b2141e94368".equals(pd.get("state_id").toString())){//逾期的逻辑处理
                    pds.put("state_id", null);
                    pds.put("yuqi_flag",DateUtil.getDay());
                }
            }
            if (null != pd.get("time")) {
                pds.put("time", pd.get("time"));
            }
            if (null != pd.get("trad_id")) {
                pds.put("trad_id", pd.get("trad_id"));
            }

            getPData(page, pds);
            // 数据权限开始
            if (null != pd.get("userid")) {
                pd.put("USER_ID", pd.get("userid"));
                PageData puser = userService.findByUserId(pd);
                if ("95bb91515192430bb7a6b5d0a0876542".equals(puser.get("USER_TYPE"))) {
                    pd.put("USER_ID", pd.get("userid"));
                    page.setPd(pd);
                    varList = billService.findBillAll(page);
                    datalayui = getLData(page, varList);
                } else {
                    //暂时注释 因为无法获取移动端传来的用户信息 2018年1月9日 17:05:16
                    PageData dataAuthPd = new PageData();
                    dataAuthPd.put("USER_ID", pd.get("userid"));
                    List<PageData> datas = roleService.dataAuthListByUserId(dataAuthPd);
                    String s = "";
                    if (datas != null && datas.size() > 0) {
                        for (int i = 0; i < datas.size(); i++) {
                            s += datas.get(i).getString("DATA_ID") + ",";
                        }
                    }
                    pds.put("USER_ID", pd.get("userid"));
                    pds.put("DATA_IDS", s);
                    page.setPd(pds);
                    PageData dataAuth = roleService.authListByLoginUser(pd);
                    if (dataAuth.get("AUTH_CODE").toString().indexOf("CWQX_ZDCK") != -1) {
                        varList = billService.findBillAll(page);
                        datalayui = getLData(page, varList);
                    }
                }
            } else {
                varList = billService.findBillAll(page);
                datalayui = getLData(page, varList);
            }
        } catch (Exception e) {
            logger.error(e.toString(), e);
        } finally {
            logAfter(logger);
        }
        return datalayui;
    }


    /**
     * 租务接口
     */
    @RequestMapping(value = "/rental")
    @ResponseBody
    public PageData rental() {
        logBefore(logger, "租务详情");
        PageData res = new PageData();
        PageData all = new PageData();
        PageData pd = this.getPageData();
        Page page = new Page();
        java.text.NumberFormat nf = java.text.NumberFormat.getInstance();//格式化科学计数法
        page.setShowCount(9999);
        //获取当前登录用户
        Subject currentUser = SecurityUtils.getSubject();
        Session session = currentUser.getSession();
        User user = (User) session.getAttribute(Const.SESSION_USER);
        try {
            //  List<PageData> list1 = billService.findRentalAll1(pd);
            pd.put("USER_ID",user.getUSER_ID());
            page.setPd(pd);
            List<PageData> list1 = contractService.findContractForCheck(page);
            int ht = list1.size();
            List<PageData> list2 = contractService.findContractForCheckBill(page);


            //  List<PageData> list2 = billService.findRentalAll2(pd);
            int zd = list2.size();
            PageData ress = new PageData();
            String a = "今日待审批合同" + ht + "个 今日待审批账单" + zd + "个";
            ress.put("TODO", a);

            pd.put("USER_ID",user.getUSER_ID());
            List<PageData> AllPriceIn = billService.AllPriceIn(pd);  //总收入
            double AllPriceIn1 = Double.parseDouble(AllPriceIn.get(0).get("AllPriceIn").toString());


            List<PageData> AllPriceOut = billService.AllPriceOut(pd);//总支出
            double AllPriceOut1 = Double.parseDouble(AllPriceOut.get(0).get("AllPriceOut").toString());
            double subtract = AllPriceIn1 - AllPriceOut1; // 净收入
            ress.put("FLOW_DETAIL", "总收入" + nf.format(AllPriceIn1) + "元/总支出" + nf.format(AllPriceOut1) + "元/净收入" + nf.format(subtract) + "元");

            all.put("USER_ID",user.getUSER_ID());
            List<PageData> Allbusiness = billService.Allbusiness(all);  //总商圈
            List<PageData> Allbuilding = billService.Allbuilding(all);  //总楼宇
            //List<PageData> Allroom = billService.Allroom(all);  //总房间
            List<PageData> Allroom = billService.totalRoom(pd);//总共的 房间数

            List<PageData> Allvacancy = billService.Operation(pd);//当前商圈 或者 时间段 入驻的房间数
            //List<PageData> Allvacancy = billService.Allvacancy(all);  //空置房间数
            // float totalroom=Integer.parseInt(totalRoom.get(0).get("totalroom").toString());
            int Allroom1 = Integer.parseInt(Allroom.get(0).get("totalroom").toString());
            int Allvacancy1 = Integer.parseInt(Allvacancy.get(0).get("inroom").toString());
            int vacancy = Allroom1 - Allvacancy1;
            ress.put("OPERATOR_REPORT", Allbusiness.get(0).get("Allbusiness") + "个商圈/" + Allbuilding.get(0).get("Allbuilding") + "栋楼/" + Allroom1 + "间/空置" + vacancy + "间");


            DecimalFormat decimalFormat = new DecimalFormat("0.00");//格式化设置
            List<PageData> price = billService.findBillprice(pd);//应收已收
            String price1 = decimalFormat.format(price.get(0).get("RECEIVE"));//应收已收
            List<PageData> prices = billService.findBillAllYS(pd);//应收
            String price2 = decimalFormat.format(prices.get(0).get("RECEIVABLE"));//应收
            //应收已收  除以  应收
            List<PageData> sumprice = billService.findBillsumprice(pd);//应收未收
            String price3 = decimalFormat.format(sumprice.get(0).get("NOT_RECEIVE"));
            ress.put("ANALYSIS", "应收¥" + nf.format(Double.valueOf(price2)) + "/已收¥" + nf.format(Double.valueOf(price1)) + "/未收¥" +  nf.format(Double.valueOf(price3)));


            List<PageData> OVER_NUM = billService.OVER_NUM(pd);//逾期账单
            int OVER_NUMSS = OVER_NUM.size();
            List<PageData> OVER_NUMOUT = billService.OVER_NUMOUT(pd);//待处理账单
            int OVER_NUMOUTSS = OVER_NUMOUT.size();
            ress.put("BILL", OVER_NUMSS + "个逾期/" + OVER_NUMOUTSS + "个待处理");


            List<PageData> CONTRACT_NUM = billService.CONTRACT_NUM(pd);//到期合同
            int CONTRACT_NUMSS = CONTRACT_NUM.size();
            List<PageData> CONTRACT_NUMOUT = billService.CONTRACT_NUMOUT(pd);//待处理合同
            int CONTRACT_NUMOUTSS = CONTRACT_NUMOUT.size();
            ress.put("CONTRACT", CONTRACT_NUMSS + "个到期/" + CONTRACT_NUMOUTSS + "个待处理");

            //贷款合同数据
            List<PageData> CONTRACT_LOAN = billService.CONTRACT_LOAN(pd);//贷款到期合同
            int CONTRACT_LOANS = CONTRACT_LOAN.size();
            ress.put("CONTRACT_LOAN", CONTRACT_LOANS + "个到期");
            //逾期的贷款账单
            List<PageData> OVER_BILL_LOAN = billService.OVER_BILL_LOAN(pd);//逾期的贷款账单
            int OVER_BILL_LOANS = OVER_BILL_LOAN.size();
            ress.put("OVER_BILL_LOAN", OVER_BILL_LOANS + "个逾期");

            res.put("data", ress);
            res.put("errcode", "0");
            res.put("errmsg", "ok");
        } catch (Exception e) {
            logger.error(e.toString(), e);
            res.put("data", "");
            res.put("errcode", "1");
            res.put("errmsg", e.toString());
        }
        return res;
    }


    /**
     * 流水明细
     */
   /* @RequestMapping(value = "/flow_detail",produces = "text/html;charset=UTF-8")
    @ResponseBody
    public Object flow_detail(Page page) {
        PageData pd = new PageData();
        PageData pds = new PageData();
        PageData one =new  PageData();
        Map<String, Object> map = new HashMap<String, Object>();
        List<PageData> newlist = new ArrayList<PageData>();
        List<PageData> varList;
        String datalayui = null;
        try {
            pd = this.getPageData();
            pds.put("page",pd.get("page"));
            pds.put("limit",pd.get("row"));

            if(null != pd.get("trad_id")){
                pds.put("trad_id",pd.get("trad_id"));
            }
            if(null != pd.get("start_time")){
                pds.put("start_time",pd.get("start_time"));
            }
            if(null != pd.get("end_time")){
                pds.put("end_time",pd.get("end_time"));
            }
            double a;
            double b=0.0;
            double c;
            PageData list2 = billService.findFlow_detail1(pd);// 总收入
            a=Double.parseDouble( list2.get("INCOMES").toString());
            BigDecimal q= new BigDecimal(a);
            double q1= q.setScale(2,BigDecimal.ROUND_HALF_UP).doubleValue();
            PageData list3 = billService.findFlow_detail2(pd);// 总支出
            if( list3.get("INCOMES").toString().equals("0")){
                b=0.0;
            }else {
                b= Double.parseDouble( list3.get("OUTCONMES").toString());
            }
            BigDecimal q2= new BigDecimal(b);
            double q3= q2.setScale(2,BigDecimal.ROUND_HALF_UP).doubleValue();
            if(b==0.0){
                c=a;
            }else {
                c= q1-q3;
            }
            BigDecimal q4= new BigDecimal(c);
            double q5= q4.setScale(2,BigDecimal.ROUND_HALF_UP).doubleValue();
            one.put("INCOMES",q1);
            one.put("OUTCONMES",q3);
            one.put("COMES",q5);
            getPData(page, pds);
            List<PageData> list1 = billService.findFlow_detail4(page);// 财务流水账单明细（list里面的数据）
            one.put("list",list1);
            newlist.add(one);
            varList = newlist;
            datalayui = getLData(page, varList);
        } catch (Exception e) {
            logger.error(e.toString(), e);
        } finally {
            logAfter(logger);
        }
        return datalayui;
    }*/


    /**
     * 流水明细
     */
    @RequestMapping(value = "/flow_detail")
    @ResponseBody
    public PageData flow_detail(Page page) {
        logBefore(logger, "财务流水详情");
        PageData res = new PageData();
        PageData pd = this.getPageData();
        //获取当前登录用户
        Subject currentUser = SecurityUtils.getSubject();
        Session session = currentUser.getSession();
        User user = (User) session.getAttribute(Const.SESSION_USER);

        try {

            pd.put("limit", pd.get("row"));
            pd.put("USER_ID",user.getUSER_ID());
            getPData(page, pd);
            PageData two = new PageData();
            PageData one = new PageData();
            DecimalFormat df = new DecimalFormat("#.00");
            double a = 0.00;
            double b = 0.00;
            double c = 0.00;
            PageData list2 = billService.findFlow_detail1(pd);// 总收入
//            a = Double.parseDouble(list2.get("INCOMES").toString());
            BigDecimal q = new BigDecimal(list2.get("INCOMES").toString());
            double q1=Double.parseDouble(list2.get("INCOMES").toString());
            System.out.println(q1);
            PageData list3 = billService.findFlow_detail2(pd);// 总支出
            if (list3.get("INCOMES").toString().equals("0")) {
                b = 0.00;
            } else {
                b = Double.parseDouble(list3.get("INCOMES").toString());
            }
            BigDecimal q2 = new BigDecimal(b);
            double q3 = q2.setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue();
            if (b == 0.00) {
                c = q1;
            } else {
                c = q1 - q3;
            }
            BigDecimal q4 = new BigDecimal(c);
            double q5 = q4.setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue();
            one.put("INCOMES", q);
            if(q3==0.0){
                one.put("OUTCONMES", "0.00");
            }else {
                one.put("OUTCONMES", df.format(q3));
            }
            one.put("COMES",df.format(q5));
            List<PageData> list1 = billService.findFlow_detail4(page);// 财务流水账单明细（list里面的数据）
            one.put("count", page.getTotalResult());
            one.put("list", list1);
            res.put("data", one);
            res.put("errcode", "0");
            res.put("errmsg", "ok");
        } catch (Exception e) {
            logger.error(e.toString(), e);
            res.put("data", "");
            res.put("errcode", "1");
            res.put("errmsg", e.toString());
        }
        return res;
    }

    /* ===============================app贷款账单开始================================== */

    /**
     * 进行中的贷款账单
     */
    @RequestMapping(value = "/billLoan",produces = "text/html;charset=UTF-8")
    @ResponseBody
    public Object contractloan(Page page) {
        PageData pd = new PageData();
        Map<String, Object> map = new HashMap<String, Object>();
        List<PageData> varList;
        String datalayui = null;
        try {
            pd = this.getPageData();
            pd.put("limit",pd.get("row"));
            pd.put("USER_ID", pd.get("userid"));
            if(!"".equals(pd.getString("amount"))&&null!=pd.getString("amount")){
                String loan_price=pd.get("amount").toString();
                //分解 贷款数
                String price[] = loan_price.split("-");
                if(price.length>1){
                    String s_price=price[0].replace("w","0000");
                    String e_price=price[1].replace("w","0000");
                    pd.put("s_price",s_price);
                    pd.put("e_price",e_price);
                }else {
                    String e_price=price[0].substring(0, price[0].indexOf("w"));
                    pd.put("s_price",e_price+"0000");
                }

            }
            if (null != pd.get("state")) {
                switch (pd.get("state").toString()){
                    case "1"://未收
                        pd.put("state", null);
                        pd.put("state", "682177ade393478e8224f9a3aa385a6c");
                        pd.put("date_in", DateUtil.getDay());
                        break;
                    case "2"://逾期
                        pd.put("state", null);
                        pd.put("state", "682177ade393478e8224f9a3aa385a6c");
                        pd.put("date_out", DateUtil.getDay());
                        break;
                    case "3"://已收
                        pd.put("state", null);
                        pd.put("state", "eda58d7280554dd9918207d27e2d4654");
                        break;
                }
            }
            getPData(page, pd);
            varList = loanService.billLoan(page);
            datalayui = getLData(page, varList);
        } catch (Exception e) {
            logger.error(e.toString(), e);
        } finally {
            logAfter(logger);
        }
        return datalayui;
    }


    /**
     * app 贷款账单详情
     */
    @RequestMapping(value = "/billLoanInfo")
    @ResponseBody
    public PageData billLoanInfo(HttpServletRequest request) {
        logBefore(logger, "");
        PageData res = new PageData();
        PageData pd = this.getPageData();
        //获取当前登录用户
        try {
            pd.put("USER_ID", pd.get("userid"));
            List<PageData> list = billService.billdetail_loan(pd);//获取租客账单基本信息
            List<PageData> list1 = billService.billdetaillist_loan(pd);//租金
            PageData list2 = billService.billdetaillistsum_loan(pd);//总金额
            PageData late_price = billService.billdetaillistLate_loan(pd);//滞纳金
            PageData ress = new PageData();
            //获取域名地址 用于组装图片全路径
            StringBuffer url = request.getRequestURL();
            String tempContextUrl = url.delete(url.length() - request.getRequestURI().length(), url.length()).append("/").toString();
            List<String> listdata = new ArrayList<>();
            PageData att = new PageData();
            att.put("id", pd.get("ID"));
            List<PageData> attachmentData = attachmentService.findByOId(att);//查看附件
            if (attachmentData.size() > 0) {
                for (int k = 0; k < attachmentData.size(); k++) {
                    listdata.add(tempContextUrl + attachmentData.get(k).get("PATH"));//存放账单详情img 数组
                }
                ress.put("PATHLIST", listdata);
            }
            ress.put("PATHLIST", listdata);
            if (null == list2) {
                ress.put("ALLPRICE", "");
            } else {
                ress.put("ALLPRICE", list2.get("ALLPRICE"));
            }
            if (list.size() > 0) {
                ress.put("SIGNER", list.get(0).get("SIGNER"));
                ress.put("START_DATE", list.get(0).get("START_DATE"));
                ress.put("END_DATE", list.get(0).get("END_DATE"));
                ress.put("TEL", list.get(0).get("TEL"));
                ress.put("INFO", list.get(0).get("INFO"));
                ress.put("STATE", list.get(0).get("STATE"));
                ress.put("PAY_DATE", list.get(0).get("PAY_DATE"));
                ress.put("REA_DATA", list.get(0).get("REA_DATA"));//实际付款时间
                if (late_price.containsKey("PRICE")&&late_price.getString("PRICE").indexOf("-")==-1) {//存在滞纳金
                    list1.add(late_price);
                    ress.put("LIST", list1);//存放账单的 租金  和 滞纳金
                } else {
                    ress.put("LIST", list1);//存放账单的 租金
                }
                //新增账单的操作权限OPERA_AUTH
               /* if (null != pd.get("userid")) {
                    pd.put("USER_ID", pd.get("userid"));
                    PageData dataAuth = roleService.authListByLoginUser(pd);
                    if(dataAuth!=null){
                        if (dataAuth.get("AUTH_CODE").toString().indexOf("SPQX_ZDSP") != -1) {
                            ress.put("OPERA_AUTH", 1);
                        } else {
                            ress.put("OPERA_AUTH", 0);
                        }
                    }else {
                        ress.put("OPERA_AUTH", 1);
                    }

                }*/
                res.put("data", ress);
            } else {
                res.put("data", "");
            }
            res.put("errcode", "0");
            res.put("errmsg", "ok");
        } catch (Exception e) {
            logger.error(e.toString(), e);
            res.put("data", "");
            res.put("errcode", "1");
            res.put("errmsg", e.toString());
        }
        return res;
    }

    /* ===============================app贷款账单结束================================== */

    /* ===============================app经营报表================================== */

    /**
     * 财务数据
     */
    @RequestMapping(value = "/price")
    @ResponseBody
    public PageData price() {
        logBefore(logger, "");
        PageData res = new PageData();
        PageData pd = this.getPageData();
        PageData data = new PageData();

        //获取当前登录用户
        Subject currentUser = SecurityUtils.getSubject();
        Session session = currentUser.getSession();
        User user = (User) session.getAttribute(Const.SESSION_USER);
        java.text.NumberFormat nf = java.text.NumberFormat.getInstance();//格式化科学计数法
        PageData datar = new PageData();//list1
        List<PageData> listin = new ArrayList<PageData>();//收入
        List<PageData> listout = new ArrayList<PageData>();//支出
        try {
            //统计权限开始  如果关闭统计权限 不统计  如果有统计权限 开启 统计
            if (null != pd.get("userid")) {
                pd.put("USER_ID", pd.get("userid"));

                if (pd.getString("TRAD") == null || !pd.getString("TRAD").equals("")) {
                    List<PageData> list = businessService.tradlist(pd);
                    String trad = "";
                    if (list != null && list.size() > 0) {
                        for (int i = 0; i < list.size(); i++) {
                            trad += list.get(i).getString("ID");
                        }
                    } else {
                        trad = "no business";
                    }
                    pd.put("TRAD", trad);
                }

                DecimalFormat decimalFormat = new DecimalFormat("0.00");//格式化设置
                DecimalFormat decimalFormat1 = new DecimalFormat("0.000000000000");//格式化设置
                List<PageData> price = billService.findBillprice(pd);//应收已收
                data.put("RECEIVE", decimalFormat.format(price.get(0).get("RECEIVE")));//应收已收
                List<PageData> price1 = billService.findBillAllYS(pd);//应收

                //应收已收  除以  应收
                BigDecimal big1 = new BigDecimal(decimalFormat.format(price1.get(0).get("RECEIVABLE")));//应收金额
                BigDecimal big2 = new BigDecimal(decimalFormat.format(price.get(0).get("RECEIVE")));//应收已收金额
                if ("0.00".equals(price.get(0).get("RECEIVE").toString())) {
                    data.put("PAYMENT_RATE", "0.00");//回款率
                } else {
                    BigDecimal sum = big2.divide(big1, 12, RoundingMode.HALF_UP);//取余
                    String aaa = decimalFormat1.format(sum);//转换成普通计数（String类型）
                    Double dbaaa = Double.valueOf(aaa) * 100;
                    BigDecimal dbbd = new BigDecimal(dbaaa);
                    Double dbaaa1 = dbbd.setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue();
                    aaa = dbaaa1 + "%";
                    data.put("PAYMENT_RATE", aaa);//回款率
                }
                List<PageData> sumprice = billService.findBillsumprice(pd);//应收未收
                data.put("NOT_RECEIVE", decimalFormat.format(sumprice.get(0).get("NOT_RECEIVE")));

                List<PageData> cashincome = billService.findBillcashincome(pd);//现金总收入
                data.put("CASH_INCOME", decimalFormat.format(cashincome.get(0).get("CASH_INCOME")));

                List<PageData> rent = billService.findBillrent(pd);//租金收入
                data.put("RENT", decimalFormat.format(rent.get(0).get("RENT")));

                List<PageData> despoit = billService.findBilldespoit(pd);//押金收入
                data.put("DESPOIT", decimalFormat.format(despoit.get(0).get("DESPOIT")));

                List<PageData> other = billService.findBillother(pd);//杂费收入
                data.put("OTHER", decimalFormat.format(other.get(0).get("OTHER")));


//===========================================


                List<PageData> findPropertyAll = billService.findPropertyAll(pd);//查询全部物业项目类型名称

                for (int i = 0; i < findPropertyAll.size(); i++) {
                    PageData datas = new PageData();//水费
                    findPropertyAll.get(i).get("CODE");
                    datas.put("NAME", findPropertyAll.get(i).get("CODE"));
                    if (null != pd.get("TRAD") && !"".equals(pd.get("TRAD").toString())) {//判断传参是否有值
                        findPropertyAll.get(i).put("TRAD", pd.get("TRAD"));
                    }
                    if (null != pd.get("START_TIME") && !"".equals(pd.get("START_TIME").toString())) {
                        findPropertyAll.get(i).put("START_TIME", pd.get("START_TIME"));
                    }
                    if (null != pd.get("END_TIME") && !"".equals(pd.get("END_TIME").toString())) {
                        findPropertyAll.get(i).put("END_TIME", pd.get("END_TIME"));
                    }
                    System.out.println(findPropertyAll.get(i));
                    List<PageData> findPropertyPrice = billService.findPropertyPrice(findPropertyAll.get(i));//查询全部物业项目类型名称
                    datas.put("PRICE", decimalFormat.format(findPropertyPrice.get(0).get("PRICE")));
                    listin.add(datas);
                }
                data.put("otherlist", listin);


                List<PageData> expend = billService.findBillexpend(pd);//现金总支出
                data.put("EXPEND", decimalFormat.format(expend.get(0).get("EXPEND")));

                List<PageData> rentout = billService.findBillrentout(pd);//租金总支出
                data.put("RENT_OUT", decimalFormat.format(rentout.get(0).get("RENT_OUT")));

                List<PageData> despoitout = billService.findBilldespoitout(pd);//押金总支出
                data.put("DESPOIT_OUT", decimalFormat.format(despoitout.get(0).get("DESPOIT_OUT")));

                List<PageData> otherout = billService.findBillotherout(pd);//杂费总支出
                data.put("OTHER_OUT", decimalFormat.format(otherout.get(0).get("OTHER_OUT")));

//=============================================

                /*   List<PageData> findPropertyAll = billService.findPropertyAll(pd);//查询全部物业项目类型名称*/

                for (int i = 0; i < findPropertyAll.size(); i++) {
                    PageData dataq = new PageData();//支出水费
                    findPropertyAll.get(i).get("CODE");
                    dataq.put("NAME", findPropertyAll.get(i).get("CODE"));
                    List<PageData> findPropertyPriceOut = billService.findPropertyPriceOut(findPropertyAll.get(i));//查询全部物业项目类型名称
                    dataq.put("PRICE", decimalFormat.format(findPropertyPriceOut.get(0).get("PRICE")));
                    listout.add(dataq);
                }
                data.put("outlist", listout);
                List<PageData> AllPriceIn = billService.findBillAllPriceIn(pd);//预计现金总收入
                data.put("EXCEPT", decimalFormat.format(AllPriceIn.get(0).get("EXCEPT")));

/*
                PageData dataAuth = roleService.authListByLoginUser(pd);
                if(null!=dataAuth){
                    if (dataAuth.get("AUTH_CODE").toString().indexOf("MENU_TJFX") != -1) {
                        DecimalFormat decimalFormat = new DecimalFormat("0.00");//格式化设置
                        DecimalFormat decimalFormat1 = new DecimalFormat("0.000000000000");//格式化设置
                        List<PageData> price = billService.findBillprice(pd);//应收已收
                        data.put("RECEIVE", decimalFormat.format(price.get(0).get("RECEIVE")));//应收已收
                        List<PageData> price1 = billService.findBillAllYS(pd);//应收

                        //应收已收  除以  应收
                        BigDecimal big1 = new BigDecimal(decimalFormat.format(price1.get(0).get("RECEIVABLE")));//应收金额
                        BigDecimal big2 = new BigDecimal(decimalFormat.format(price.get(0).get("RECEIVE")));//应收已收金额
                        if ("0.00".equals(price.get(0).get("RECEIVE").toString())) {
                            data.put("PAYMENT_RATE", "0.00");//回款率
                        } else {
                            BigDecimal sum = big2.divide(big1, 12, RoundingMode.HALF_UP);//取余
                            String aaa = decimalFormat1.format(sum);//转换成普通计数（String类型）
                            data.put("PAYMENT_RATE", aaa);//回款率
                        }
                        List<PageData> sumprice = billService.findBillsumprice(pd);//应收未收
                        data.put("NOT_RECEIVE", decimalFormat.format(sumprice.get(0).get("NOT_RECEIVE")));

                        List<PageData> cashincome = billService.findBillcashincome(pd);//现金总收入
                        data.put("CASH_INCOME", decimalFormat.format(cashincome.get(0).get("CASH_INCOME")));

                        List<PageData> rent = billService.findBillrent(pd);//租金收入
                        data.put("RENT", decimalFormat.format(rent.get(0).get("RENT")));

                        List<PageData> despoit = billService.findBilldespoit(pd);//押金收入
                        data.put("DESPOIT", decimalFormat.format(despoit.get(0).get("DESPOIT")));

                        List<PageData> other = billService.findBillother(pd);//杂费收入
                        data.put("OTHER", decimalFormat.format(other.get(0).get("OTHER")));


//===========================================


                        List<PageData> findPropertyAll = billService.findPropertyAll(pd);//查询全部物业项目类型名称

                        for (int i = 0; i < findPropertyAll.size(); i++) {
                            PageData datas = new PageData();//水费
                            findPropertyAll.get(i).get("CODE");
                            datas.put("NAME", findPropertyAll.get(i).get("CODE"));
                            if (null != pd.get("TRAD") && !"".equals(pd.get("TRAD").toString())) {//判断传参是否有值
                                findPropertyAll.get(i).put("TRAD", pd.get("TRAD"));
                            }
                            if (null != pd.get("START_TIME") && !"".equals(pd.get("START_TIME").toString())) {
                                findPropertyAll.get(i).put("START_TIME", pd.get("START_TIME"));
                            }
                            if (null != pd.get("END_TIME") && !"".equals(pd.get("END_TIME").toString())) {
                                findPropertyAll.get(i).put("END_TIME", pd.get("END_TIME"));
                            }
                            System.out.println(findPropertyAll.get(i));
                            List<PageData> findPropertyPrice = billService.findPropertyPrice(findPropertyAll.get(i));//查询全部物业项目类型名称
                            datas.put("PRICE", decimalFormat.format(findPropertyPrice.get(0).get("PRICE")));
                            listin.add(datas);
                        }
                        data.put("otherlist", listin);


                        List<PageData> expend = billService.findBillexpend(pd);//现金总支出
                        data.put("EXPEND", decimalFormat.format(expend.get(0).get("EXPEND")));

                        List<PageData> rentout = billService.findBillrentout(pd);//租金总支出
                        data.put("RENT_OUT", decimalFormat.format(rentout.get(0).get("RENT_OUT")));

                        List<PageData> despoitout = billService.findBilldespoitout(pd);//押金总支出
                        data.put("DESPOIT_OUT", decimalFormat.format(despoitout.get(0).get("DESPOIT_OUT")));

                        List<PageData> otherout = billService.findBillotherout(pd);//杂费总支出
                        data.put("OTHER_OUT", decimalFormat.format(otherout.get(0).get("OTHER_OUT")));

//=============================================

                        *//*   List<PageData> findPropertyAll = billService.findPropertyAll(pd);//查询全部物业项目类型名称*//*

                        for (int i = 0; i < findPropertyAll.size(); i++) {
                            PageData dataq = new PageData();//支出水费
                            findPropertyAll.get(i).get("CODE");
                            dataq.put("NAME", findPropertyAll.get(i).get("CODE"));
                            List<PageData> findPropertyPriceOut = billService.findPropertyPriceOut(findPropertyAll.get(i));//查询全部物业项目类型名称
                            dataq.put("PRICE", decimalFormat.format(findPropertyPriceOut.get(0).get("PRICE")));
                            listout.add(dataq);
                        }
                        data.put("outlist", listout);
                        List<PageData> AllPriceIn = billService.findBillAllPriceIn(pd);//预计现金总收入
                        data.put("EXCEPT", decimalFormat.format(AllPriceIn.get(0).get("EXCEPT")));

                    }
                }
            } else {
                DecimalFormat decimalFormat = new DecimalFormat("0.00");//格式化设置
                DecimalFormat decimalFormat1 = new DecimalFormat("0.000000000000");//格式化设置
                List<PageData> price = billService.findBillprice(pd);//应收已收
                data.put("RECEIVE", decimalFormat.format(price.get(0).get("RECEIVE")));//应收已收
                List<PageData> price1 = billService.findBillAllYS(pd);//应收

                //应收已收  除以  应收
                BigDecimal big1 = new BigDecimal(decimalFormat.format(price1.get(0).get("RECEIVABLE")));//应收金额
                BigDecimal big2 = new BigDecimal(decimalFormat.format(price.get(0).get("RECEIVE")));//应收已收金额
                if ("0.00".equals(price.get(0).get("RECEIVE").toString())) {
                    data.put("PAYMENT_RATE", "0.00");//回款率
                } else {
                    BigDecimal sum = big2.divide(big1, 12, RoundingMode.HALF_UP);//取余
                    String aaa = decimalFormat1.format(sum);//转换成普通计数（String类型）
                    data.put("PAYMENT_RATE", aaa);//回款率
                }
                List<PageData> sumprice = billService.findBillsumprice(pd);//应收未收
                data.put("NOT_RECEIVE", decimalFormat.format(sumprice.get(0).get("NOT_RECEIVE")));

                List<PageData> cashincome = billService.findBillcashincome(pd);//现金总收入
                data.put("CASH_INCOME", decimalFormat.format(cashincome.get(0).get("CASH_INCOME")));

                List<PageData> rent = billService.findBillrent(pd);//租金收入
                data.put("RENT", decimalFormat.format(rent.get(0).get("RENT")));

                List<PageData> despoit = billService.findBilldespoit(pd);//押金收入
                data.put("DESPOIT", decimalFormat.format(despoit.get(0).get("DESPOIT")));

                List<PageData> other = billService.findBillother(pd);//杂费收入
                data.put("OTHER", decimalFormat.format(other.get(0).get("OTHER")));


//===========================================


                List<PageData> findPropertyAll = billService.findPropertyAll(pd);//查询全部物业项目类型名称

                for (int i = 0; i < findPropertyAll.size(); i++) {
                    PageData datas = new PageData();//水费
                    findPropertyAll.get(i).get("CODE");
                    datas.put("NAME", findPropertyAll.get(i).get("CODE"));
                    if (null != pd.get("TRAD") && !"".equals(pd.get("TRAD").toString())) {//判断传参是否有值
                        findPropertyAll.get(i).put("TRAD", pd.get("TRAD"));
                    }
                    if (null != pd.get("START_TIME") && !"".equals(pd.get("START_TIME").toString())) {
                        findPropertyAll.get(i).put("START_TIME", pd.get("START_TIME"));
                    }
                    if (null != pd.get("END_TIME") && !"".equals(pd.get("END_TIME").toString())) {
                        findPropertyAll.get(i).put("END_TIME", pd.get("END_TIME"));
                    }
                    System.out.println(findPropertyAll.get(i));
                    List<PageData> findPropertyPrice = billService.findPropertyPrice(findPropertyAll.get(i));//查询全部物业项目类型名称
                    datas.put("PRICE", decimalFormat.format(findPropertyPrice.get(0).get("PRICE")));
                    listin.add(datas);
                }
                data.put("otherlist", listin);


                List<PageData> expend = billService.findBillexpend(pd);//现金总支出
                data.put("EXPEND", decimalFormat.format(expend.get(0).get("EXPEND")));

                List<PageData> rentout = billService.findBillrentout(pd);//租金总支出
                data.put("RENT_OUT", decimalFormat.format(rentout.get(0).get("RENT_OUT")));

                List<PageData> despoitout = billService.findBilldespoitout(pd);//押金总支出
                data.put("DESPOIT_OUT", decimalFormat.format(despoitout.get(0).get("DESPOIT_OUT")));

                List<PageData> otherout = billService.findBillotherout(pd);//杂费总支出
                data.put("OTHER_OUT", decimalFormat.format(otherout.get(0).get("OTHER_OUT")));

//=============================================

                *//*   List<PageData> findPropertyAll = billService.findPropertyAll(pd);//查询全部物业项目类型名称*//*

                for (int i = 0; i < findPropertyAll.size(); i++) {
                    PageData dataq = new PageData();//支出水费
                    findPropertyAll.get(i).get("CODE");
                    dataq.put("NAME", findPropertyAll.get(i).get("CODE"));
                    List<PageData> findPropertyPriceOut = billService.findPropertyPriceOut(findPropertyAll.get(i));//查询全部物业项目类型名称
                    dataq.put("PRICE", decimalFormat.format(findPropertyPriceOut.get(0).get("PRICE")));
                    listout.add(dataq);
                }
                data.put("outlist", listout);
                List<PageData> AllPriceIn = billService.findBillAllPriceIn(pd);//预计现金总收入
                data.put("EXCEPT", decimalFormat.format(AllPriceIn.get(0).get("EXCEPT")));*/

            }
            //统计权限结束
            res.put("list", data);
            res.put("errcode", "0");
            res.put("errmsg", "ok");
        } catch (Exception e) {
            logger.error(e.toString(), e);
            res.put("data", "");
            res.put("errcode", "1");
            res.put("errmsg", e.toString());
        }
        return res;
    }

    /**
     * 运营数据
     */
    @RequestMapping(value = "/Operation")
    @ResponseBody
    public PageData Operation() {
        logBefore(logger, "运营数据");
        PageData res = new PageData();
        PageData pd = this.getPageData();
        PageData data = new PageData();

        //获取当前登录用户
        Subject currentUser = SecurityUtils.getSubject();
        Session session = currentUser.getSession();
        User user = (User) session.getAttribute(Const.SESSION_USER);

        try {
            //统计权限开始  如果关闭统计权限 不统计  如果有统计权限 开启 统计
            if (null != pd.get("userid")) {
                pd.put("USER_ID", pd.get("userid"));

                List<PageData> list = billService.Operation(pd);//当前商圈 或者 时间段 入驻的房间数
                List<PageData> totalRoom = billService.totalRoom(pd);//总共的 房间数
                List<PageData> outRoom = billService.outRoom(pd);//退租 商户 数
                List<PageData> allBill = billService.allBill(pd);//总账单数
                List<PageData> RECE_NUM = billService.RECE_NUM(pd);//应收账单数
                List<PageData> OVER_NUM = billService.OVER_NUM(pd);//逾期账单
                List<PageData> COLLECT_NUM = billService.COLLECT_NUM(pd);//代收款账单数
                if (list.size() > 0) {
                    int inroom = Integer.parseInt(list.get(0).get("inroom").toString());
                    int totalroom = Integer.parseInt(totalRoom.get(0).get("totalroom").toString());
                    NumberFormat nt = NumberFormat.getPercentInstance(); //获取格式化对象
                    nt.setMinimumFractionDigits(2);    //设置百分数精确度2即保留两位小数
                    //System.out.println(nt.format(inroom / totalroom));
                    if (totalroom != 0) {
                        DecimalFormat df = new DecimalFormat("0.0000");//格式化小数
                        String num = df.format((float)inroom/totalroom);//返回的是String类型
                        float sss=(Float.parseFloat(num))*1;
                        data.put("OCCUPANCY_RATE",nt.format(sss)); //入住率
                    } else {
                        data.put("OCCUPANCY_RATE", nt.format(0)); //入住率
                    }
                    data.put("ALL_ROOM", (int) totalroom + "间");                    //总房间
                    int VACANT = totalroom - inroom;                          //空置房间
                    data.put("VACANT", (int) VACANT + "间");
                    data.put("NEW_ROOM", (int) inroom + "间"); //新签房间
                }
                if (outRoom.size() > 0) {
                    data.put("OUT_ROOM", outRoom.get(0).get("outRoom") + "间");//退租商户 房间数
                }
                //总账单数 应收款账单数 逾期账单数 代收款账单数
                if (allBill.size() > 0) {
                    data.put("ALL_BILL", allBill.get(0).get("allBill") + "个");//总账单数
                }
                if (RECE_NUM.size() > 0) {
                    data.put("RECE_NUM", RECE_NUM.get(0).get("RECE_NUM") + "个");//应收款
                }
                if (OVER_NUM.size() > 0) {
                    data.put("OVER_NUM", OVER_NUM.size() + "个");//逾期账单 数
                }
                if (COLLECT_NUM.size() > 0) {
                    data.put("COLLECT_NUM", COLLECT_NUM.get(0).get("COLLECT_NUM") + "个");//代收款账单数
                }
            }//统计权限结束



                /*PageData dataAuth = roleService.authListByLoginUser(pd);
                if(null!=dataAuth){
                    if (dataAuth.get("AUTH_CODE").toString().indexOf("MENU_TJFX") != -1) {
                        List<PageData> list = billService.Operation(pd);//当前商圈 或者 时间段 入驻的房间数
                        List<PageData> totalRoom = billService.totalRoom(pd);//总共的 房间数
                        List<PageData> outRoom = billService.outRoom(pd);//退租 商户 数
                        List<PageData> allBill = billService.allBill(pd);//总账单数
                        List<PageData> RECE_NUM = billService.RECE_NUM(pd);//应收账单数
                        List<PageData> OVER_NUM = billService.OVER_NUM(pd);//逾期账单
                        List<PageData> COLLECT_NUM = billService.COLLECT_NUM(pd);//代收款账单数
                        if (list.size() > 0) {
                            int inroom = Integer.parseInt(list.get(0).get("inroom").toString());
                            int totalroom = Integer.parseInt(totalRoom.get(0).get("totalroom").toString());
                            NumberFormat nt = NumberFormat.getPercentInstance(); //获取格式化对象
                            nt.setMinimumFractionDigits(2);    //设置百分数精确度2即保留两位小数
                            //System.out.println(nt.format(inroom / totalroom));
                            if (totalroom != 0) {
                                DecimalFormat df = new DecimalFormat("0.0000");//格式化小数
                                String num = df.format((float)inroom/totalroom);//返回的是String类型
                                float sss=(Float.parseFloat(num))*1;
                                data.put("OCCUPANCY_RATE",nt.format(sss)); //入住率
                            } else {
                                data.put("OCCUPANCY_RATE", nt.format(0)); //入住率
                            }
                            data.put("ALL_ROOM", (int) totalroom + "间");                    //总房间
                            int VACANT = totalroom - inroom;                          //空置房间
                            data.put("VACANT", (int) VACANT + "间");
                            data.put("NEW_ROOM", (int) inroom + "间"); //新签房间
                        }
                        if (outRoom.size() > 0) {
                            data.put("OUT_ROOM", outRoom.get(0).get("outRoom") + "间");//退租商户 房间数
                        }
                        //总账单数 应收款账单数 逾期账单数 代收款账单数
                        if (allBill.size() > 0) {
                            data.put("ALL_BILL", allBill.get(0).get("allBill") + "个");//总账单数
                        }
                        if (RECE_NUM.size() > 0) {
                            data.put("RECE_NUM", RECE_NUM.get(0).get("RECE_NUM") + "个");//应收款
                        }
                        if (OVER_NUM.size() > 0) {
                            data.put("OVER_NUM", OVER_NUM.size() + "个");//逾期账单 数
                        }
                        if (COLLECT_NUM.size() > 0) {
                            data.put("COLLECT_NUM", COLLECT_NUM.get(0).get("COLLECT_NUM") + "个");//代收款账单数
                        }
                    }//统计权限结束
                }
            } else {
                List<PageData> list = billService.Operation(pd);//当前商圈 或者 时间段 入驻的房间数
                List<PageData> totalRoom = billService.totalRoom(pd);//总共的 房间数
                List<PageData> outRoom = billService.outRoom(pd);//退租 商户 数
                List<PageData> allBill = billService.allBill(pd);//总账单数
                List<PageData> RECE_NUM = billService.RECE_NUM(pd);//应收账单数
                List<PageData> OVER_NUM = billService.OVER_NUM(pd);//逾期账单
                List<PageData> COLLECT_NUM = billService.COLLECT_NUM(pd);//代收款账单数
                if (list.size() > 0) {
                    int inroom = Integer.parseInt(list.get(0).get("inroom").toString());
                    int totalroom = Integer.parseInt(totalRoom.get(0).get("totalroom").toString());
                    NumberFormat nt = NumberFormat.getPercentInstance(); //获取格式化对象
                    nt.setMinimumFractionDigits(2);    //设置百分数精确度2即保留两位小数
                    //System.out.println(nt.format(inroom / totalroom));
                    if (totalroom != 0) {
                        data.put("OCCUPANCY_RATE", nt.format(inroom / totalroom)); //入住率
                    } else {
                        data.put("OCCUPANCY_RATE", nt.format(0)); //入住率
                    }
                    data.put("ALL_ROOM", (int) totalroom + "间");                    //总房间
                    int VACANT = totalroom - inroom;                          //空置房间
                    data.put("VACANT", (int) VACANT + "间");
                    data.put("NEW_ROOM", (int) inroom + "间"); //新签房间
                }
                if (outRoom.size() > 0) {
                    data.put("OUT_ROOM", outRoom.get(0).get("outRoom") + "间");//退租商户 房间数
                }
                //总账单数 应收款账单数 逾期账单数 代收款账单数
                if (allBill.size() > 0) {
                    data.put("ALL_BILL", allBill.get(0).get("allBill") + "个");//总账单数
                }
                if (RECE_NUM.size() > 0) {
                    data.put("RECE_NUM", RECE_NUM.get(0).get("RECE_NUM") + "个");//应收款
                }
                if (OVER_NUM.size() > 0) {
                    data.put("OVER_NUM", OVER_NUM.size() + "个");//逾期账单 数
                }
                if (COLLECT_NUM.size() > 0) {
                    data.put("COLLECT_NUM", COLLECT_NUM.get(0).get("COLLECT_NUM") + "个");//代收款账单数
                }
            }*/
            res.put("data", data);
            res.put("errcode", "0");
            res.put("errmsg", "ok");
        } catch (Exception e) {
            logger.error(e.toString(), e);
            res.put("data", "");
            res.put("errcode", "1");
            res.put("errmsg", e.toString());
        }
        return res;
    }

    /**
     * 账单和合同的状态接口
     */
    @RequestMapping(value = "/state")
    @ResponseBody
    public PageData state() {
        logBefore(logger, "账单和合同的状态接口");
        PageData res = new PageData();
        PageData pd = this.getPageData();
        try {
            List<PageData> list = billService.findbill_contracttype(pd);
            res.put("data", list);
            res.put("errcode", "0");
            res.put("errmsg", "ok");
        } catch (Exception e) {
            logger.error(e.toString(), e);
            res.put("data", "");
            res.put("errcode", "1");
            res.put("errmsg", e.toString());
        }
        return res;
    }

    /* ===============================app经营报表结束================================== */
    /**
     * 导出到excel 应收
     *
     * @return
     */
    @RequestMapping(value = "/excel")
    @ResponseBody
    public ModelAndView exportExcel() {
        logBefore(logger, "导出Bill到excel");
        ModelAndView mv = new ModelAndView();
        Page page = this.getPage();
        PageData pd = this.getPageData();

        Map map1 = JSONHelper.json2Map(pd.toString().replace("[","{").replace("]","}"));
        JSONObject jo = (JSONObject) map1.get("DATA");

        pd.put("START_DATE", jo.get("START_DATE"));
        pd.put("END_DATE", jo.get("END_DATE"));
        pd.put("COMPANY_NAME", jo.get("COMPANY_NAME"));
        pd.put("BILL_NAME", jo.get("BILL_NAME"));
        pd.put("BYNAME", jo.get("BYNAME"));
        pd.put("TOTAL_PRICE", jo.get("TOTAL_PRICE"));
        pd.put("TOTAL_PRICE_STA", jo.get("TOTAL_PRICE_STA"));
        pd.put("TOTAL_PRICE_END", jo.get("TOTAL_PRICE_END"));
        pd.put("BUSINESS_ID", jo.get("BUSINESS_ID"));
        pd.put("BUILDING_ID", jo.get("BUILDING_ID"));
        pd.put("ALL_DATA", jo.get("ALL_DATA"));

        page.setShowCount(10000);
        page.setPd(pd);
        try {
            Map<String, Object> dataMap = new HashMap<String, Object>();
            List<String> titles = new ArrayList<String>();
            titles.add("楼宇名称");
            titles.add("房号");
            titles.add("承租方");
            titles.add("别名");
            titles.add("联系方式");
            titles.add("账单周期");
            titles.add("账单类型");
            titles.add("账单金额");
            titles.add("应收租日");
            titles.add("收费类型");
            titles.add("生成类型");
            titles.add("账单状态");
            titles.add("备注");
            dataMap.put("titles", titles);
            List<PageData> varOList = billService.listAll(page);
            List<PageData> varList = new ArrayList<PageData>();
            for (int i = 0; i < varOList.size(); i++) {
                PageData vpd = new PageData();
                vpd.put("var1", varOList.get(i).getString("BUILDING_NAME"));
                vpd.put("var2", varOList.get(i).getString("ROOM_NUM"));
                vpd.put("var3", varOList.get(i).getString("COMPANY_NAME"));
                vpd.put("var4", varOList.get(i).getString("BYNAME"));
                vpd.put("var5", varOList.get(i).getString("SIGNER_TEL"));
                vpd.put("var6", varOList.get(i).getString("START_DATE"));
                vpd.put("var7", varOList.get(i).getString("BILL_NAME"));
                vpd.put("var8", varOList.get(i).getString("TOTAL_PRICE"));
                vpd.put("var9", varOList.get(i).getString("PAY_DATE"));
                vpd.put("var10", varOList.get(i).getString("ALLOT_BILL"));
                vpd.put("var11", varOList.get(i).getString("MAKE_BILL_TYPE"));
                vpd.put("var12", varOList.get(i).getString("STATE"));
                vpd.put("var13", varOList.get(i).getString("INFO"));
                varList.add(vpd);
            }
            dataMap.put("varList", varList);
            ObjectExcelView erv = new ObjectExcelView();
            mv = new ModelAndView(erv, dataMap);
        } catch (Exception e) {
            logger.error(e.toString(), e);
        }
        return mv;
    }

    /**
     * 导出到excel 已收
     *
     * @return
     */
    @RequestMapping(value = "/excel_yichuli")
    @ResponseBody
    public ModelAndView excel_yichuli() {
        logBefore(logger, "导出Bill到excel");
        ModelAndView mv = new ModelAndView();
        Page page = this.getPage();
        PageData pd = this.getPageData();

        Map map1 = JSONHelper.json2Map(pd.toString().replace("[","{").replace("]","}"));
        JSONObject jo = (JSONObject) map1.get("DATA");

//        pd.put("START_DATE", jo.get("START_DATE"));
//        pd.put("END_DATE", jo.get("END_DATE"));
        pd.put("COMPANY_NAME", jo.get("COMPANY_NAME"));
        pd.put("BILL_NAME", jo.get("BILL_NAME"));
        pd.put("BYNAME", jo.get("BYNAME"));
        pd.put("TOTAL_PRICE", jo.get("TOTAL_PRICE"));
        pd.put("TOTAL_PRICE_STA", jo.get("TOTAL_PRICE_STA"));
        pd.put("TOTAL_PRICE_END", jo.get("TOTAL_PRICE_END"));
        pd.put("BUSINESS_ID", jo.get("BUSINESS_ID"));
        pd.put("BUILDING_ID", jo.get("BUILDING_ID"));
        pd.put("ALL_DATA", jo.get("ALL_DATA"));

        page.setShowCount(10000);
        page.setPd(pd);
        try {
            Map<String, Object> dataMap = new HashMap<String, Object>();
            List<String> titles = new ArrayList<String>();
            titles.add("楼宇名称");
            titles.add("房号");
            titles.add("承租方");
            titles.add("别名");
            titles.add("实收金额");
            titles.add("账单周期");
            titles.add("账单类型");
            titles.add("账单金额");
            titles.add("应收租日");
            titles.add("收费类型");
            titles.add("生成类型");
            titles.add("账单状态");
            titles.add("备注");
            dataMap.put("titles", titles);
            List<PageData> varOList= billService.listPayOk(page);
            List<PageData> varList = new ArrayList<PageData>();
            for (int i = 0; i < varOList.size(); i++) {
                PageData vpd = new PageData();
                vpd.put("var1", varOList.get(i).getString("BUILDING_NAME"));
                vpd.put("var2", varOList.get(i).getString("ROOM_NUM"));
                vpd.put("var3", varOList.get(i).getString("COMPANY_NAME"));
                vpd.put("var4", varOList.get(i).getString("BYNAME"));
                vpd.put("var5", varOList.get(i).getString("PAY_PRICE"));
                vpd.put("var6", varOList.get(i).getString("START_DATE"));
                vpd.put("var7", varOList.get(i).getString("BILL_NAME"));
                vpd.put("var8", varOList.get(i).getString("TOTAL_PRICE"));
                vpd.put("var9", varOList.get(i).getString("PAY_DATE"));
                vpd.put("var10", varOList.get(i).getString("ALLOT_BILL"));
                vpd.put("var11", varOList.get(i).getString("MAKE_BILL_TYPE"));
                vpd.put("var12", varOList.get(i).getString("STATE"));
                vpd.put("var13", varOList.get(i).getString("INFO"));
                varList.add(vpd);
            }
            dataMap.put("varList", varList);
            ObjectExcelView erv = new ObjectExcelView();
            mv = new ModelAndView(erv, dataMap);
        } catch (Exception e) {
            logger.error(e.toString(), e);
        }
        return mv;
    }

    /**
     * 导出到excel 已收
     *
     * @return
     */
    @RequestMapping(value = "/excel_yingfu")
    @ResponseBody
    public ModelAndView excel_yingfu() {
        logBefore(logger, "导出Bill到excel");
        ModelAndView mv = new ModelAndView();
        Page page = this.getPage();
        PageData pd = this.getPageData();

        Map map1 = JSONHelper.json2Map(pd.toString().replace("[","{").replace("]","}"));
        JSONObject jo = (JSONObject) map1.get("DATA");

//        pd.put("START_DATE", jo.get("START_DATE"));
//        pd.put("END_DATE", jo.get("END_DATE"));
        pd.put("COMPANY_NAME", jo.get("COMPANY_NAME"));
        pd.put("BILL_NAME", jo.get("BILL_NAME"));
        pd.put("BYNAME", jo.get("BYNAME"));
        pd.put("TOTAL_PRICE", jo.get("TOTAL_PRICE"));
        pd.put("TOTAL_PRICE_STA", jo.get("TOTAL_PRICE_STA"));
        pd.put("TOTAL_PRICE_END", jo.get("TOTAL_PRICE_END"));
        pd.put("BUSINESS_ID", jo.get("BUSINESS_ID"));
        pd.put("BUILDING_ID", jo.get("BUILDING_ID"));
        pd.put("ALL_DATA", jo.get("ALL_DATA"));

        page.setShowCount(10000);
        page.setPd(pd);
        try {
            Map<String, Object> dataMap = new HashMap<String, Object>();
            List<String> titles = new ArrayList<String>();
            titles.add("楼宇名称");
            titles.add("房号");
            titles.add("承租方");
            titles.add("别名");
            titles.add("应付金额");
            titles.add("账单周期");
            titles.add("账单类型");
            titles.add("账单金额");
            titles.add("应收租日");
            titles.add("收费类型");
            titles.add("生成类型");
            titles.add("备注");
            dataMap.put("titles", titles);
            List<PageData> varOList= billService.listyingfu(page);
            List<PageData> varList = new ArrayList<PageData>();
            for (int i = 0; i < varOList.size(); i++) {
                PageData vpd = new PageData();
                vpd.put("var1", varOList.get(i).getString("BUILDING_NAME"));
                vpd.put("var2", varOList.get(i).getString("ROOM_NUM"));
                vpd.put("var3", varOList.get(i).getString("COMPANY_NAME"));
                vpd.put("var4", varOList.get(i).getString("BYNAME"));
                vpd.put("var5", varOList.get(i).getString("PAY_PRICE"));
                vpd.put("var6", varOList.get(i).getString("START_DATE"));
                vpd.put("var7", varOList.get(i).getString("BILL_NAME"));
                vpd.put("var8", varOList.get(i).getString("TOTAL_PRICE"));
                vpd.put("var9", varOList.get(i).getString("PAY_DATE"));
                vpd.put("var10", varOList.get(i).getString("ALLOT_BILL"));
                vpd.put("var11", varOList.get(i).getString("MAKE_BILL_TYPE"));
                vpd.put("var12", varOList.get(i).getString("INFO"));
                varList.add(vpd);
            }
            dataMap.put("varList", varList);
            ObjectExcelView erv = new ObjectExcelView();
            mv = new ModelAndView(erv, dataMap);
        } catch (Exception e) {
            logger.error(e.toString(), e);
        }
        return mv;
    }

    /**
     * 导出到excel 逾期
     *
     * @return
     */
    @RequestMapping(value = "/excel_yuqi")
    @ResponseBody
    public ModelAndView excel_yuqi() {
        logBefore(logger, "导出Bill到excel");
        ModelAndView mv = new ModelAndView();
        Page page = this.getPage();
        PageData pd = this.getPageData();

        Map map1 = JSONHelper.json2Map(pd.toString().replace("[","{").replace("]","}"));
        JSONObject jo = (JSONObject) map1.get("DATA");

//        pd.put("START_DATE", jo.get("START_DATE"));
//        pd.put("END_DATE", jo.get("END_DATE"));
        pd.put("COMPANY_NAME", jo.get("COMPANY_NAME"));
        pd.put("BILL_NAME", jo.get("BILL_NAME"));
        pd.put("BYNAME", jo.get("BYNAME"));
        pd.put("TOTAL_PRICE", jo.get("TOTAL_PRICE"));
        pd.put("TOTAL_PRICE_STA", jo.get("TOTAL_PRICE_STA"));
        pd.put("TOTAL_PRICE_END", jo.get("TOTAL_PRICE_END"));
        pd.put("BUSINESS_ID", jo.get("BUSINESS_ID"));
        pd.put("BUILDING_ID", jo.get("BUILDING_ID"));
        pd.put("ALL_DATA", jo.get("ALL_DATA"));

        page.setShowCount(10000);
        page.setPd(pd);
        try {
            Map<String, Object> dataMap = new HashMap<String, Object>();
            List<String> titles = new ArrayList<String>();
            titles.add("楼宇名称");
            titles.add("房号");
            titles.add("承租方");
            titles.add("别名");
            titles.add("账单金额");
            titles.add("账单周期");
            titles.add("逾期天数");
            titles.add("账单类型");
            titles.add("滞纳金");
            titles.add("应收租日");
            titles.add("收费类型");
            titles.add("生成类型");
            titles.add("备注");
            dataMap.put("titles", titles);
            List<PageData> varOList= billService.listPayyuqi(page);
            List<PageData> varList = new ArrayList<PageData>();
            for (int i = 0; i < varOList.size(); i++) {
                PageData vpd = new PageData();
                vpd.put("var1", varOList.get(i).getString("BUILDING_NAME"));
                vpd.put("var2", varOList.get(i).getString("ROOM_NUM"));
                vpd.put("var3", varOList.get(i).getString("COMPANY_NAME"));
                vpd.put("var4", varOList.get(i).getString("BYNAME"));
                vpd.put("var5", varOList.get(i).getString("TOTAL_PRICE"));
                vpd.put("var6", varOList.get(i).getString("START_DATE"));
                vpd.put("var7", varOList.get(i).get("LATE_DAY").toString());
                vpd.put("var8", varOList.get(i).getString("BILL_NAME"));
                vpd.put("var9", varOList.get(i).getString("LATE_FEE"));
                vpd.put("var10", varOList.get(i).getString("PAY_DATE"));
                vpd.put("var11", varOList.get(i).getString("ALLOT_BILL"));
                vpd.put("var12", varOList.get(i).getString("MAKE_BILL_TYPE"));
                vpd.put("var13", varOList.get(i).getString("INFO"));
                varList.add(vpd);
            }
            dataMap.put("varList", varList);
            ObjectExcelView erv = new ObjectExcelView();
            mv = new ModelAndView(erv, dataMap);
        } catch (Exception e) {
            logger.error(e.toString(), e);
        }
        return mv;
    }

    /**
     * 导出到excel 逾期
     *
     * @return
     */
    @RequestMapping(value = "/excel_ziyong")
    @ResponseBody
    public ModelAndView excel_ziyong() {
        logBefore(logger, "导出Bill到excel");
        ModelAndView mv = new ModelAndView();
        Page page = this.getPage();
        PageData pd = this.getPageData();

        Map map1 = JSONHelper.json2Map(pd.toString().replace("[","{").replace("]","}"));
        JSONObject jo = (JSONObject) map1.get("DATA");

//        pd.put("START_DATE", jo.get("START_DATE"));
//        pd.put("END_DATE", jo.get("END_DATE"));
        pd.put("COMPANY_NAME", jo.get("COMPANY_NAME"));
        pd.put("BILL_NAME", jo.get("BILL_NAME"));
        pd.put("BYNAME", jo.get("BYNAME"));
        pd.put("TOTAL_PRICE", jo.get("TOTAL_PRICE"));
        pd.put("TOTAL_PRICE_STA", jo.get("TOTAL_PRICE_STA"));
        pd.put("TOTAL_PRICE_END", jo.get("TOTAL_PRICE_END"));
        pd.put("BUSINESS_ID", jo.get("BUSINESS_ID"));
        pd.put("BUILDING_ID", jo.get("BUILDING_ID"));
        pd.put("ALL_DATA", jo.get("ALL_DATA"));

        page.setShowCount(10000);
        page.setPd(pd);
        try {
            Map<String, Object> dataMap = new HashMap<String, Object>();
            List<String> titles = new ArrayList<String>();
            titles.add("项目编号");
            titles.add("账单金额");
            titles.add("账单周期");
            titles.add("账单类型");
            titles.add("应收租日");
            titles.add("收费类型");
            titles.add("生成类型");
            titles.add("备注");
            dataMap.put("titles", titles);
            List<PageData> varOList= billService.listPayziyong(page);
            List<PageData> varList = new ArrayList<PageData>();
            for (int i = 0; i < varOList.size(); i++) {
                PageData vpd = new PageData();
                vpd.put("var1", varOList.get(i).getString("ROOM_NUM"));
                vpd.put("var2", varOList.get(i).getString("TOTAL_PRICE"));
                vpd.put("var3", varOList.get(i).getString("START_DATE"));
                vpd.put("var4", varOList.get(i).getString("BILL_NAME"));
                vpd.put("var5", varOList.get(i).getString("PAY_DATE"));
                vpd.put("var6", varOList.get(i).getString("ALLOT_BILL"));
                vpd.put("var7", varOList.get(i).getString("MAKE_BILL_TYPE"));
                vpd.put("var8", varOList.get(i).getString("INFO"));
                varList.add(vpd);
            }
            dataMap.put("varList", varList);
            ObjectExcelView erv = new ObjectExcelView();
            mv = new ModelAndView(erv, dataMap);
        } catch (Exception e) {
            logger.error(e.toString(), e);
        }
        return mv;
    }

    /**
     * 导出到excel 流水明细 shouru
     *
     * @return
     */
    @RequestMapping(value = "/excel_shouru")
    @ResponseBody
    public ModelAndView excel_shouru() {
        logBefore(logger, "导出Bill到excel");
        ModelAndView mv = new ModelAndView();
        Page page = this.getPage();
        PageData pd = this.getPageData();

        Map map1 = JSONHelper.json2Map(pd.toString().replace("[","{").replace("]","}"));
        JSONObject jo = (JSONObject) map1.get("DATA");

//        pd.put("START_DATE", jo.get("START_DATE"));
//        pd.put("END_DATE", jo.get("END_DATE"));
        pd.put("COMPANY_NAME", jo.get("COMPANY_NAME"));
        pd.put("BILL_NAME", jo.get("BILL_NAME"));
        pd.put("BYNAME", jo.get("BYNAME"));
        pd.put("TOTAL_PRICE", jo.get("TOTAL_PRICE"));
        pd.put("TOTAL_PRICE_STA", jo.get("TOTAL_PRICE_STA"));
        pd.put("TOTAL_PRICE_END", jo.get("TOTAL_PRICE_END"));
        pd.put("BUSINESS_ID", jo.get("BUSINESS_ID"));
        pd.put("BUILDING_ID", jo.get("BUILDING_ID"));
        pd.put("ALL_DATA", jo.get("ALL_DATA"));
        pd.put("PRICE_TYPE", "0");//0 shouru   1 zhichu
        page.setShowCount(10000);
        page.setPd(pd);
        try {
            Map<String, Object> dataMap = new HashMap<String, Object>();
            List<String> titles = new ArrayList<String>();
            titles.add("楼宇名称");
            titles.add("房号");
            titles.add("承租方");
            titles.add("别名");
            titles.add("支付金额");
            titles.add("账单周期");
            titles.add("账单类型");
            titles.add("备注");
            dataMap.put("titles", titles);
            List<PageData> varOList= billService.listshouru(page);
            List<PageData> varList = new ArrayList<PageData>();
            for (int i = 0; i < varOList.size(); i++) {
                PageData vpd = new PageData();
                vpd.put("var1", varOList.get(i).getString("BUILDING_NAME"));
                vpd.put("var2", varOList.get(i).getString("ROOM_NUM"));
                vpd.put("var3", varOList.get(i).getString("COMPANY_NAME"));
                vpd.put("var4", varOList.get(i).getString("BYNAME"));
                vpd.put("var5", varOList.get(i).get("PAY_PRICE").toString());
                vpd.put("var6", varOList.get(i).getString("START_DATE"));
                vpd.put("var7", varOList.get(i).getString("BILL_NAME"));
                vpd.put("var8", varOList.get(i).getString("INFO"));
                varList.add(vpd);
            }
            dataMap.put("varList", varList);
            ObjectExcelView erv = new ObjectExcelView();
            mv = new ModelAndView(erv, dataMap);
        } catch (Exception e) {
            logger.error(e.toString(), e);
        }
        return mv;
    }

    /**
     * 导出到excel 流水明细 shouru
     *
     * @return
     */
    @RequestMapping(value = "/excel_zhichu")
    @ResponseBody
    public ModelAndView excel_zhichu() {
        logBefore(logger, "导出Bill到excel");
        ModelAndView mv = new ModelAndView();
        Page page = this.getPage();
        PageData pd = this.getPageData();

        Map map1 = JSONHelper.json2Map(pd.toString().replace("[","{").replace("]","}"));
        JSONObject jo = (JSONObject) map1.get("DATA");

//        pd.put("START_DATE", jo.get("START_DATE"));
//        pd.put("END_DATE", jo.get("END_DATE"));
        pd.put("COMPANY_NAME", jo.get("COMPANY_NAME"));
        pd.put("BILL_NAME", jo.get("BILL_NAME"));
        pd.put("BYNAME", jo.get("BYNAME"));
        pd.put("TOTAL_PRICE", jo.get("TOTAL_PRICE"));
        pd.put("TOTAL_PRICE_STA", jo.get("TOTAL_PRICE_STA"));
        pd.put("TOTAL_PRICE_END", jo.get("TOTAL_PRICE_END"));
        pd.put("BUSINESS_ID", jo.get("BUSINESS_ID"));
        pd.put("BUILDING_ID", jo.get("BUILDING_ID"));
        pd.put("ALL_DATA", jo.get("ALL_DATA"));
        pd.put("PRICE_TYPE", "1");//0 shouru   1 zhichu
        page.setShowCount(10000);
        page.setPd(pd);
        try {
            Map<String, Object> dataMap = new HashMap<String, Object>();
            List<String> titles = new ArrayList<String>();
            titles.add("楼宇名称");
            titles.add("房号");
            titles.add("承租方");
            titles.add("别名");
            titles.add("支付金额");
            titles.add("账单周期");
            titles.add("账单类型");
            titles.add("备注");
            dataMap.put("titles", titles);
            List<PageData> varOList= billService.listshouru(page);
            List<PageData> varList = new ArrayList<PageData>();
            for (int i = 0; i < varOList.size(); i++) {
                PageData vpd = new PageData();
                vpd.put("var1", varOList.get(i).getString("BUILDING_NAME"));
                vpd.put("var2", varOList.get(i).getString("ROOM_NUM"));
                vpd.put("var3", varOList.get(i).getString("COMPANY_NAME"));
                vpd.put("var4", varOList.get(i).getString("BYNAME"));
                vpd.put("var5", varOList.get(i).get("PAY_PRICE").toString());
                vpd.put("var6", varOList.get(i).getString("START_DATE"));
                vpd.put("var7", varOList.get(i).getString("BILL_NAME"));
                vpd.put("var8", varOList.get(i).getString("INFO"));
                varList.add(vpd);
            }
            dataMap.put("varList", varList);
            ObjectExcelView erv = new ObjectExcelView();
            mv = new ModelAndView(erv, dataMap);
        } catch (Exception e) {
            logger.error(e.toString(), e);
        }
        return mv;
    }

    /**
     * 导出到excel 收入预算
     *
     * @return
     */
    @RequestMapping(value = "/excel_srys")
    @ResponseBody
    public ModelAndView excel_srys() {
        logBefore(logger, "导出Bill到excel");
        ModelAndView mv = new ModelAndView();
        Page page = this.getPage();
        PageData pd = this.getPageData();

        Map map1 = JSONHelper.json2Map(pd.toString().replace("[","{").replace("]","}"));
        JSONObject jo = (JSONObject) map1.get("DATA");

        pd.put("START_DATE", jo.get("START_DATE"));
        pd.put("END_DATE", jo.get("END_DATE"));
        pd.put("COMPANY_NAME", jo.get("COMPANY_NAME"));
        pd.put("BILL_NAME", jo.get("BILL_NAME"));
        pd.put("BYNAME", jo.get("BYNAME"));
        pd.put("TOTAL_PRICE", jo.get("TOTAL_PRICE"));
        pd.put("TOTAL_PRICE_STA", jo.get("TOTAL_PRICE_STA"));
        pd.put("TOTAL_PRICE_END", jo.get("TOTAL_PRICE_END"));
        pd.put("BUSINESS_ID", jo.get("BUSINESS_ID"));
        pd.put("BUILDING_ID", jo.get("BUILDING_ID"));
        pd.put("ALL_DATA", jo.get("ALL_DATA"));

        page.setShowCount(10000);
        page.setPd(pd);
        try {
            Map<String, Object> dataMap = new HashMap<String, Object>();
            List<String> titles = new ArrayList<String>();
            titles.add("楼宇名称");
            titles.add("房号");
            titles.add("承租方");
            titles.add("别名");
            titles.add("联系方式");
            titles.add("账单周期");
            titles.add("账单类型");
            titles.add("账单金额");
            titles.add("应收租日");
            titles.add("收费类型");
            titles.add("生成类型");
            titles.add("账单状态");
            titles.add("备注");
            dataMap.put("titles", titles);
            List<PageData> varOList = billService.listshouruyusuan(page);
            List<PageData> varList = new ArrayList<PageData>();
            for (int i = 0; i < varOList.size(); i++) {
                PageData vpd = new PageData();
                vpd.put("var1", varOList.get(i).getString("BUILDING_NAME"));
                vpd.put("var2", varOList.get(i).getString("ROOM_NUM"));
                vpd.put("var3", varOList.get(i).getString("COMPANY_NAME"));
                vpd.put("var4", varOList.get(i).getString("BYNAME"));
                vpd.put("var5", varOList.get(i).getString("SIGNER_TEL"));
                vpd.put("var6", varOList.get(i).getString("START_DATE"));
                vpd.put("var7", varOList.get(i).getString("BILL_NAME"));
                vpd.put("var8", varOList.get(i).getString("TOTAL_PRICE"));
                vpd.put("var9", varOList.get(i).getString("PAY_DATE"));
                vpd.put("var10", varOList.get(i).getString("ALLOT_BILL"));
                vpd.put("var11", varOList.get(i).getString("MAKE_BILL_TYPE"));
                vpd.put("var12", varOList.get(i).getString("STATE"));
                vpd.put("var13", varOList.get(i).getString("INFO"));
                varList.add(vpd);
            }
            dataMap.put("varList", varList);
            ObjectExcelView erv = new ObjectExcelView();
            mv = new ModelAndView(erv, dataMap);
        } catch (Exception e) {
            logger.error(e.toString(), e);
        }
        return mv;
    }

    /**
     * 导出到excel 退租结算
     *
     * @return
     */
    @RequestMapping(value = "/excel_tzjs")
    @ResponseBody
    public ModelAndView excel_tzjs() {
        logBefore(logger, "导出Bill到excel");
        ModelAndView mv = new ModelAndView();
        Page page = this.getPage();
        PageData pd = this.getPageData();

        Map map1 = JSONHelper.json2Map(pd.toString().replace("[","{").replace("]","}"));
        JSONObject jo = (JSONObject) map1.get("DATA");

        pd.put("START_DATE", jo.get("START_DATE"));
        pd.put("END_DATE", jo.get("END_DATE"));
        pd.put("COMPANY_NAME", jo.get("COMPANY_NAME"));
        pd.put("BILL_NAME", jo.get("BILL_NAME"));
        pd.put("BYNAME", jo.get("BYNAME"));
        pd.put("TOTAL_PRICE", jo.get("TOTAL_PRICE"));
        pd.put("TOTAL_PRICE_STA", jo.get("TOTAL_PRICE_STA"));
        pd.put("TOTAL_PRICE_END", jo.get("TOTAL_PRICE_END"));
        pd.put("BUSINESS_ID", jo.get("BUSINESS_ID"));
        pd.put("BUILDING_ID", jo.get("BUILDING_ID"));
        pd.put("ALL_DATA", jo.get("ALL_DATA"));

        page.setShowCount(10000);
        page.setPd(pd);
        try {
            Map<String, Object> dataMap = new HashMap<String, Object>();
            List<String> titles = new ArrayList<String>();
            titles.add("楼宇名称");
            titles.add("房号");
            titles.add("承租方");
            titles.add("别名");
            titles.add("退租日期");
            titles.add("状态");
            titles.add("账单类型");
            titles.add("账单金额");
            titles.add("生成类型");
            titles.add("备注");
            dataMap.put("titles", titles);
            List<PageData> varOList = billService.listtzjs(page);
            List<PageData> varList = new ArrayList<PageData>();
            for (int i = 0; i < varOList.size(); i++) {
                PageData vpd = new PageData();
                vpd.put("var1", varOList.get(i).getString("BUILDING_NAME"));
                vpd.put("var2", varOList.get(i).getString("ROOM_NUM"));
                vpd.put("var3", varOList.get(i).getString("COMPANY_NAME"));
                vpd.put("var4", varOList.get(i).getString("BYNAME"));
                vpd.put("var5", varOList.get(i).getString("PAY_DATE"));
                vpd.put("var6", varOList.get(i).getString("BILL_STATE"));
                vpd.put("var7", varOList.get(i).getString("BILL_NAME"));
                vpd.put("var8", varOList.get(i).getString("TOTAL_PRICE"));
                vpd.put("var9", varOList.get(i).getString("MAKE_BILL_TYPE"));
                vpd.put("var10", varOList.get(i).getString("INFO"));
                varList.add(vpd);
            }
            dataMap.put("varList", varList);
            ObjectExcelView erv = new ObjectExcelView();
            mv = new ModelAndView(erv, dataMap);
        } catch (Exception e) {
            logger.error(e.toString(), e);
        }
        return mv;
    }

    /**
     * 导出到excel 审批账单
     *
     * @return
     */
    @RequestMapping(value = "/excel_spzd")
    @ResponseBody
    public ModelAndView excel_spzd() {
        logBefore(logger, "导出Bill到excel");
        ModelAndView mv = new ModelAndView();
        Page page = this.getPage();
        PageData pd = this.getPageData();

        Map map1 = JSONHelper.json2Map(pd.toString().replace("[","{").replace("]","}"));
        JSONObject jo = (JSONObject) map1.get("DATA");

        pd.put("START_DATE", jo.get("START_DATE"));
        pd.put("END_DATE", jo.get("END_DATE"));
        pd.put("COMPANY_NAME", jo.get("COMPANY_NAME"));
        pd.put("BILL_NAME", jo.get("BILL_NAME"));
        pd.put("BYNAME", jo.get("BYNAME"));
        pd.put("TOTAL_PRICE", jo.get("TOTAL_PRICE"));
        pd.put("TOTAL_PRICE_STA", jo.get("TOTAL_PRICE_STA"));
        pd.put("TOTAL_PRICE_END", jo.get("TOTAL_PRICE_END"));
        pd.put("BUSINESS_ID", jo.get("BUSINESS_ID"));
        pd.put("BUILDING_ID", jo.get("BUILDING_ID"));
        pd.put("ALL_DATA", jo.get("ALL_DATA"));

        page.setShowCount(10000);
        page.setPd(pd);
        try {
            Map<String, Object> dataMap = new HashMap<String, Object>();
            List<String> titles = new ArrayList<String>();
            titles.add("楼宇名称");
            titles.add("房号");
            titles.add("承租方");
            titles.add("别名");
            titles.add("账单周期");
            titles.add("账单类型");
            titles.add("账单金额");
            titles.add("备注");
            titles.add("提交人");
            titles.add("提交时间");
            titles.add("状态");
            dataMap.put("titles", titles);
            List<PageData> varOList= billService.billshenpi(page);
            List<PageData> varList = new ArrayList<PageData>();
            for (int i = 0; i < varOList.size(); i++) {
                PageData vpd = new PageData();
                vpd.put("var1", varOList.get(i).getString("BUILDING_NAME"));
                vpd.put("var2", varOList.get(i).getString("ROOM_NUM"));
                vpd.put("var3", varOList.get(i).getString("COMPANY_NAME"));
                vpd.put("var4", varOList.get(i).getString("BYNAME"));
                vpd.put("var5", varOList.get(i).getString("START_DATE"));
                vpd.put("var6", varOList.get(i).getString("BILL_NAME"));
                vpd.put("var7", varOList.get(i).getString("TOTAL_PRICE"));
                vpd.put("var8", varOList.get(i).getString("INFO"));
                vpd.put("var9", varOList.get(i).getString("CREATE_ID"));
                vpd.put("var10", varOList.get(i).getString("CREATE_DATE"));
                vpd.put("var11", varOList.get(i).getString("STATE"));
                varList.add(vpd);
            }
            dataMap.put("varList", varList);
            ObjectExcelView erv = new ObjectExcelView();
            mv = new ModelAndView(erv, dataMap);
        } catch (Exception e) {
            logger.error(e.toString(), e);
        }
        return mv;
    }
}





